public static Combo createEncodingCombo(Composite parent, String curCharset) { if (curCharset == null) { curCharset = GeneralUtils.getDefaultFileEncoding(); } Combo encodingCombo = new Combo(parent, SWT.DROP_DOWN); encodingCombo.setVisibleItemCount(30); SortedMap<String, Charset> charsetMap = Charset.availableCharsets(); int index = 0; int defIndex = -1; for (String csName : charsetMap.keySet()) { Charset charset = charsetMap.get(csName); encodingCombo.add(charset.displayName()); if (charset.displayName().equalsIgnoreCase(curCharset)) { defIndex = index; } if (defIndex < 0) { for (String alias : charset.aliases()) { if (alias.equalsIgnoreCase(curCharset)) { defIndex = index; } } } index++; } if (defIndex >= 0) { encodingCombo.select(defIndex); } else { log.warn("Charset '" + curCharset + "' is not recognized"); // $NON-NLS-1$ //$NON-NLS-2$ } return encodingCombo; }
public static boolean setComboSelection(Combo combo, String value) { if (value == null) { return false; } int count = combo.getItemCount(); for (int i = 0; i < count; i++) { if (value.equals(combo.getItem(i))) { combo.select(i); return true; } } return false; }
public void createFileFilterPanel(Shell dialog) { Composite filterPanel = new Composite(dialog, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); filterPanel.setLayoutData(gridData); filterPanel.setLayout(new GridLayout(3, false)); // create filter label Label filterLabel = new Label(filterPanel, SWT.NONE); filterLabel.setText(Messages.getString("VfsFileChooserDialog.filter")); // $NON-NLS-1$ gridData = new GridData(SWT.FILL, SWT.CENTER, false, false); filterLabel.setLayoutData(gridData); // create file filter combo fileFilterCombo = new Combo(filterPanel, SWT.READ_ONLY); gridData = new GridData(SWT.FILL, SWT.FILL, true, false); fileFilterCombo.setLayoutData(gridData); fileFilterCombo.setItems(fileFilterNames); fileFilterCombo.addSelectionListener(this); fileFilterCombo.select(0); }
public void populateCustomUIPanel(Shell dialog) { ArrayList<String> customNames = new ArrayList<String>(); for (int i = 0; i < customUIPanels.size(); i++) { CustomVfsUiPanel panel = customUIPanels.get(i); if (panel.getVfsScheme().equalsIgnoreCase("file") || schemeRestrictions == null || isRestrictedTo(panel.getVfsScheme())) { if (panel.getVfsScheme().equalsIgnoreCase("file") && !showFileScheme) { continue; } customNames.add(panel.getVfsSchemeDisplayText()); } } customUIPicker.setItems(customNames.toArray(new String[] {})); hideCustomPanelChildren(); // hide entire panel if no customizations if (customNames.size() == 0) { customUIPanel.setParent(fakeShell); } else { if (customNames.size() == 1 && "file".equals(customNames.get(0))) { customUIPanel.setParent(fakeShell); } else { String initialSchemeDisplayText = initialScheme; for (int i = 0; i < customUIPanels.size(); i++) { if (customUIPanels.get(i).getVfsScheme().equalsIgnoreCase(initialScheme)) { initialSchemeDisplayText = customUIPanels.get(i).getVfsSchemeDisplayText(); break; } } for (int i = 0; i < customUIPicker.getItemCount(); i++) { if (customUIPicker.getItem(i).equalsIgnoreCase(initialSchemeDisplayText)) { customUIPicker.select(i); customUIPicker.notifyListeners(SWT.Selection, null); } } } } }
public void updateParentFileCombo(FileObject selectedItem) { try { List<FileObject> parentChain = new ArrayList<FileObject>(); // are we a directory? try { if (selectedItem.getType() == FileType.FOLDER && selectedItem.getType().hasChildren()) { // we have real children.... parentChain.add(selectedItem); } } catch (Exception e) { // we are not a folder } FileObject parentFileObject; parentFileObject = selectedItem.getParent(); while (parentFileObject != null) { parentChain.add(parentFileObject); parentFileObject = parentFileObject.getParent(); } File roots[] = File.listRoots(); if (currentPanel != null) { for (int i = 0; i < roots.length; i++) { parentChain.add(currentPanel.resolveFile(roots[i].getAbsolutePath())); } } String items[] = new String[parentChain.size()]; int idx = 0; for (int i = parentChain.size() - 1; i >= 0; i--) { items[idx++] = ((FileObject) parentChain.get(i)).getName().getURI(); } openFileCombo.setItems(items); openFileCombo.select(items.length - 1); } catch (Exception e) { e.printStackTrace(); // then let's not update the GUI } }
/* (non-Javadoc) * @see org.eclipse.pde.internal.ui.wizards.target.TargetDefinitionPage#targetChanged() */ protected void targetChanged(ITargetDefinition definition) { super.targetChanged(definition); if (definition != null) { // When If the page isn't open yet, try running a UI job so the dialog has time to finish // opening new UIJob(PDEUIMessages.TargetDefinitionContentPage_0) { public IStatus runInUIThread(IProgressMonitor monitor) { ITargetDefinition definition = getTargetDefinition(); if (!definition.isResolved()) { try { getContainer() .run( true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { getTargetDefinition().resolve(new ResolutionProgressMonitor(monitor)); if (monitor.isCanceled()) { throw new InterruptedException(); } } }); } catch (InvocationTargetException e) { PDECore.log(e); } catch (InterruptedException e) { fContentTree.setCancelled(); return Status.CANCEL_STATUS; } } fContentTree.setInput(definition); fLocationTree.setInput(definition); if (definition.isResolved() && definition.getStatus().getSeverity() == IStatus.ERROR) { fLocationTab.setImage( PlatformUI.getWorkbench() .getSharedImages() .getImage(ISharedImages.IMG_OBJS_ERROR_TSK)); } else { fLocationTab.setImage(null); } return Status.OK_STATUS; } }.schedule(); String name = definition.getName(); if (name == null) { name = EMPTY_STRING; } if (name.trim().length() > 0) fNameText.setText(name); else setMessage(PDEUIMessages.TargetDefinitionContentPage_8); fLocationTree.setInput(definition); fContentTree.setInput(definition); String presetValue = (definition.getOS() == null) ? EMPTY_STRING : definition.getOS(); fOSCombo.setText(presetValue); presetValue = (definition.getWS() == null) ? EMPTY_STRING : definition.getWS(); fWSCombo.setText(presetValue); presetValue = (definition.getArch() == null) ? EMPTY_STRING : definition.getArch(); fArchCombo.setText(presetValue); presetValue = (definition.getNL() == null) ? EMPTY_STRING : LocaleUtil.expandLocaleName(definition.getNL()); fNLCombo.setText(presetValue); IPath jrePath = definition.getJREContainer(); if (jrePath == null || jrePath.equals(JavaRuntime.newDefaultJREContainerPath())) { fDefaultJREButton.setSelection(true); } else { String ee = JavaRuntime.getExecutionEnvironmentId(jrePath); if (ee != null) { fExecEnvButton.setSelection(true); fExecEnvsCombo.select(fExecEnvsCombo.indexOf(ee)); } else { String vm = JavaRuntime.getVMInstallName(jrePath); if (vm != null) { fNamedJREButton.setSelection(true); fNamedJREsCombo.select(fNamedJREsCombo.indexOf(vm)); } } } if (fExecEnvsCombo.getSelectionIndex() == -1) fExecEnvsCombo.setText(fExecEnvChoices.first().toString()); if (fNamedJREsCombo.getSelectionIndex() == -1) fNamedJREsCombo.setText(VMUtil.getDefaultVMInstallName()); updateJREWidgets(); presetValue = (definition.getProgramArguments() == null) ? EMPTY_STRING : definition.getProgramArguments(); fProgramArgs.setText(presetValue); presetValue = (definition.getVMArguments() == null) ? EMPTY_STRING : definition.getVMArguments(); fVMArgs.setText(presetValue); fElementViewer.refresh(); } }
/** * Constructor to create an editor to update/create an ontology entry * * @param display - points back to the display * @param oureditOntEntry - the entry being edited * @param ontParent - the edited item's parent in the hierarchy * @param newItem - true if this is a new item */ public EditOntEntry( Display display, OntEntry oureditOntEntry, OntEntry ontParent, boolean newItem) { super(); shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL); shell.setText("OntEntry Information"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 5; gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); ourOntEntry = oureditOntEntry; ourParent = ontParent; if (newItem) { ourOntEntry.setName(""); ourOntEntry.setImportance(Importance.MODERATE); } new Label(shell, SWT.NONE).setText("Name:"); nameField = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL); nameField.setText(ourOntEntry.getName()); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); DisplayUtilities.setTextDimensions(nameField, gridData, 75); gridData.horizontalSpan = 2; nameField.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Description:"); descArea = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); descArea.setText(ourOntEntry.getDescription()); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); DisplayUtilities.setTextDimensions(descArea, gridData, 75, 5); gridData.horizontalSpan = 2; gridData.heightHint = descArea.getLineHeight() * 3; descArea.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Importance:"); importanceBox = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); Enumeration impEnum = Importance.elements(); int l = 0; Importance itype; while (impEnum.hasMoreElements()) { itype = (Importance) impEnum.nextElement(); importanceBox.add(itype.toString()); if (itype.toString().compareTo(ourOntEntry.getImportance().toString()) == 0) { importanceBox.select(l); } l++; } // Error checking: if no such selection is valid, set it to select index 0 if (importanceBox.getSelectionIndex() == -1) { importanceBox.select(0); } importanceBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(shell, SWT.NONE).setText(" "); new Label(shell, SWT.NONE).setText(" "); addButton = new Button(shell, SWT.PUSH); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); addButton.setLayoutData(gridData); if (newItem) { addButton.setText("Add"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; if (!nameField.getText().trim().equals("")) { ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourParent.addChild(ourOntEntry); ourOntEntry.setLevel(ourParent.getLevel() + 1); ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // comment before this made no sense... ourOntEntry.setID(ourOntEntry.toDatabase(ourParent.getID())); System.out.println("Name of added item = " + ourOntEntry.getName()); shell.close(); shell.dispose(); } } else { MessageBox mbox = new MessageBox(shell, SWT.ICON_ERROR); mbox.setMessage("Need to provide the OntEntry name"); mbox.open(); } } }); } else { addButton.setText("Save"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // since this is a save, not an add, the type and parent are ignored ourOntEntry.setID(ourOntEntry.toDatabase(0)); // RationaleDB db = RationaleDB.getHandle(); // db.addOntEntry(ourOntEntry); shell.close(); shell.dispose(); } } }); } cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); cancelButton.setLayoutData(gridData); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = true; shell.close(); shell.dispose(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }