List of usage examples for org.eclipse.jface.dialogs Dialog Dialog
protected Dialog(IShellProvider parentShell)
From source file:org.eclipse.ui.texteditor.ChangeEncodingAction.java
License:Open Source License
public void run() { final IResource resource = getResource(); final Shell parentShell = getTextEditor().getSite().getShell(); final IEncodingSupport encodingSupport = getEncodingSupport(); if (resource == null && encodingSupport == null) { MessageDialog.openInformation(parentShell, fDialogTitle, TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport); return;/*from ww w . j a v a 2s .c o m*/ } Dialog dialog = new Dialog(parentShell) { private AbstractEncodingFieldEditor fEncodingEditor; private IPreferenceStore store = null; /* * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(fDialogTitle); } /* * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); composite = new Composite(composite, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); composite.setLayout(layout); GridData data = new GridData(GridData.FILL_BOTH); composite.setLayoutData(data); composite.setFont(parent.getFont()); DialogPage page = new MessageDialogPage(composite) { public void setErrorMessage(String newMessage) { super.setErrorMessage(newMessage); setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null); setButtonEnabledState(APPLY_ID, newMessage == null); } private void setButtonEnabledState(int id, boolean state) { Button button = getButton(id); if (button != null) button.setEnabled(state); } }; if (resource != null) { fEncodingEditor = new ResourceEncodingFieldEditor("", composite, resource, null); //$NON-NLS-1$ fEncodingEditor.setPage(page); fEncodingEditor.load(); } else { fEncodingEditor = new EncodingFieldEditor(ENCODING_PREF_KEY, "", null, composite); //$NON-NLS-1$ store = new PreferenceStore(); String defaultEncoding = encodingSupport.getDefaultEncoding(); store.setDefault(ENCODING_PREF_KEY, defaultEncoding); String encoding = encodingSupport.getEncoding(); if (encoding != null) store.setValue(ENCODING_PREF_KEY, encoding); fEncodingEditor.setPreferenceStore(store); fEncodingEditor.setPage(page); fEncodingEditor.load(); if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0) fEncodingEditor.loadDefault(); } return composite; } /* * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ protected void createButtonsForButtonBar(Composite parent) { createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false); super.createButtonsForButtonBar(parent); } /* * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) */ protected void buttonPressed(int buttonId) { if (buttonId == APPLY_ID) apply(); else super.buttonPressed(buttonId); } /* * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ protected void okPressed() { apply(); super.okPressed(); } private void apply() { fEncodingEditor.store(); if (resource == null) { String encoding = fEncodingEditor.getPreferenceStore() .getString(fEncodingEditor.getPreferenceName()); encodingSupport.setEncoding(encoding); } } }; dialog.open(); }
From source file:org.jfree.experimental.chart.swt.editor.SWTChartEditorDialog.java
License:Open Source License
/** * Creates a new editor./*ww w . j a v a 2 s. c om*/ * * @param shell2 the display. * @param chart2edit the chart to edit. */ public SWTChartEditorDialog(Shell shell2, final JFreeChart chart2edit) { this.dialog = new Dialog(shell2) { @Override protected Control createDialogArea(Composite parent) { SWTChartEditorDialog.this.chart = chart2edit; GridLayout layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; parent.setLayout(layout); Composite main = new Composite(parent, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); main.setSize(400, 500); TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + localizationResources.getString("Title") + " "); SWTChartEditorDialog.this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, SWTChartEditorDialog.this.chart.getTitle()); item1.setControl(SWTChartEditorDialog.this.titleEditor); // build second tab TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + localizationResources.getString("Plot") + " "); SWTChartEditorDialog.this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, SWTChartEditorDialog.this.chart.getPlot()); item2.setControl(SWTChartEditorDialog.this.plotEditor); // build the third tab TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + localizationResources.getString("Other") + " "); SWTChartEditorDialog.this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, SWTChartEditorDialog.this.chart); item3.setControl(SWTChartEditorDialog.this.otherEditor); return super.createDialogArea(parent); } @Override protected void buttonPressed(int buttonId) { if (buttonId == 0) { updateChart(SWTChartEditorDialog.this.chart); } this.close(); } }; }
From source file:org.locationtech.udig.catalog.tests.ui.workflow.BasicWorkflowTest.java
License:Open Source License
@Test public void testNonBlocking() { Shell shell = new Shell(Display.getDefault()); final Dialog dialog = new Dialog(shell) { };//from w w w . j a v a2 s . c om Listener1 l = new Listener1() { @Override public void finished(State state) { super.finished(state); Display.getDefault().asyncExec(new Runnable() { public void run() { dialog.close(); } }); } }; pipe.addListener(l); pipe.start(); pipe.next(); pipe.next(); pipe.next(); pipe.next(); pipe.next(); //need to open a dialog here to "halt" the ui thread so that the // the workbench doesn't close while the pipe is still running dialog.setBlockOnOpen(true); dialog.open(); if (!shell.isDisposed()) shell.dispose(); assertTrue(l.state1); assertTrue(l.state2); assertTrue(l.state3); assertTrue(l.state4); assertTrue(l.state5); assertTrue(l.finished); assertTrue(!l.fail); assertEquals(i, 6); assertNotNull(pipe.getState(State1.class)); assertNotNull(pipe.getState(State2.class)); assertNotNull(pipe.getState(State3.class)); assertNotNull(pipe.getState(State4.class)); assertNotNull(pipe.getState(State5.class)); assertTrue(pipe.getState(State1.class).ran); assertTrue(pipe.getState(State2.class).ran); assertTrue(pipe.getState(State3.class).ran); assertTrue(pipe.getState(State4.class).ran); assertTrue(pipe.getState(State5.class).ran); }
From source file:org.locationtech.udig.catalog.tests.ui.workflow.BasicWorkflowTest.java
License:Open Source License
@Ignore @Test//from w w w . j av a 2s . c om public void testStateFailureNonBlocking() { Shell shell = new Shell(Display.getDefault()); final Dialog dialog = new Dialog(shell) { }; //test where one state craps out s4.run = false; Listener1 l = new Listener2() { @Override public void stateFailed(State state) { super.stateFailed(state); if (dialog.getShell().isVisible()) { dialog.getShell().getDisplay().asyncExec(new Runnable() { public void run() { dialog.close(); }; }); } } @Override public void finished(State state) { super.finished(state); dialog.close(); } }; pipe.addListener(l); pipe.start(); pipe.next(); pipe.next(); pipe.next(); pipe.next(); pipe.next(); //need to open a dialog here to "halt" the ui thread so that the // the workbench doesn't close while the pipe is still running // create a watchdog to kill it after a specified amount of time Runnable runnable = new Runnable() { public void run() { System.out.println("Running"); //$NON-NLS-1$ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Is dialog active dialog"); //$NON-NLS-1$ Display.getDefault().syncExec(new Runnable() { public void run() { if (dialog.getShell().isVisible()) { dialog.close(); } } }); } }; new Thread(runnable).start(); dialog.setBlockOnOpen(true); if (!l.finished) dialog.open(); if (!shell.isDisposed()) shell.dispose(); assertTrue(l.state1); assertTrue(l.state2); assertTrue(l.state3); assertTrue(!l.state4); assertTrue(!l.state5); assertTrue(!l.finished); assertTrue(!l.fail); assertEquals(i, 4); assertNotNull(pipe.getState(State1.class)); assertNotNull(pipe.getState(State2.class)); assertNotNull(pipe.getState(State3.class)); assertNotNull(pipe.getState(State4.class)); assertNull(pipe.getState(State5.class)); assertTrue(pipe.getState(State1.class).ran); assertTrue(pipe.getState(State2.class).ran); assertTrue(pipe.getState(State3.class).ran); assertTrue(pipe.getState(State4.class).ran); assertEquals(pipe.getCurrentState(), s4); }
From source file:org.locationtech.udig.omsbox.ui.SettingsDialog.java
License:Open Source License
public void open(Shell parentShell, final int selectionType) { resourcesList = new ArrayList<String>(); String[] retrieveSavedJars = OmsBoxPlugin.getDefault().retrieveSavedJars(); for (String jarPath : retrieveSavedJars) { resourcesList.add(jarPath);//w w w . j a va 2 s . co m } dialog = new Dialog(parentShell) { @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(""); //$NON-NLS-1$ } @Override protected Point getInitialSize() { return new Point(640, 450); } @Override protected Control createDialogArea(Composite parent) { Composite parentPanel = (Composite) super.createDialogArea(parent); final TabFolder tabFolder = new TabFolder(parentPanel, SWT.NONE); GridData tabFolderGD = new GridData(SWT.FILL, SWT.FILL, true, true); tabFolder.setLayoutData(tabFolderGD); TabItem librariesTabItem = new TabItem(tabFolder, SWT.NULL); librariesTabItem.setText("General Settings"); Composite librariesPanel = new Composite(tabFolder, SWT.NONE); librariesPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); librariesPanel.setLayout(new GridLayout(2, true)); createWorkingFolderText(librariesPanel); final Group librariesGroup = new Group(librariesPanel, SWT.None); GridData librariesGroupGD = new GridData(SWT.FILL, SWT.FILL, true, true); librariesGroupGD.horizontalSpan = 2; librariesGroup.setLayoutData(librariesGroupGD); librariesGroup.setLayout(new GridLayout(2, false)); librariesGroup.setText("Modules Libraries"); createTableViewer(librariesGroup); createAddRemoveButtons(librariesGroup); librariesTabItem.setControl(librariesPanel); TabItem grassTabItem = new TabItem(tabFolder, SWT.NULL); grassTabItem.setText("Grass settings"); Composite grassPanel = new Composite(tabFolder, SWT.NONE); grassPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); grassPanel.setLayout(new GridLayout(1, false)); grassTabItem.setControl(grassPanel); createGrassPanel(grassPanel); return parentPanel; } @Override protected void buttonPressed(int buttonId) { if (buttonId == OK) { OmsBoxPlugin.getDefault().saveJars(resourcesList); cancelPressed = false; } else { cancelPressed = true; } super.buttonPressed(buttonId); } }; dialog.setBlockOnOpen(true); dialog.open(); }
From source file:org.locationtech.udig.omsbox.view.widgets.GuiTextField.java
License:Open Source License
@Override public Control makeGui(Composite parent) { int cols = 1; if (isInFile || isInFolder || isOutFile || isOutFolder || isCrs || isMultiline) { cols = 2;/* w w w.j a v a 2 s.c om*/ } final boolean isFile = isInFile || isOutFile; final boolean isFolder = isInFolder || isOutFolder; parent = new Composite(parent, SWT.NONE); parent.setLayoutData(constraints); GridLayout layout = new GridLayout(cols, false); layout.marginWidth = 0; layout.marginHeight = 0; parent.setLayout(layout); if (!isMultiline) { text = new StyledText(parent, SWT.RIGHT | SWT.BORDER); GridData textGD = new GridData(SWT.FILL, SWT.CENTER, true, false); textGD.widthHint = 100; text.setLayoutData(textGD); // text.setLineAlignment(0, 1, SWT.RIGHT); } else if (isMapcalc) { text = MapcalculatorUtils.createMapcalcPanel(parent, rows); } else { text = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.LEAD | SWT.BORDER | SWT.V_SCROLL); GridData textGD = new GridData(SWT.FILL, SWT.CENTER, true, true); textGD.verticalSpan = rows; textGD.widthHint = 100; text.setLayoutData(textGD); } text.addModifyListener(this); text.addFocusListener(this); if (data.fieldValue != null) { String tmp = data.fieldValue; if (tmp.contains(OmsBoxConstants.WORKINGFOLDER)) { // check if there is a working folder defined String workingFolder = OmsBoxPlugin.getDefault().getWorkingFolder(); workingFolder = checkBackSlash(workingFolder, true); if (workingFolder != null) { tmp = tmp.replaceFirst(OmsBoxConstants.WORKINGFOLDER, workingFolder); data.fieldValue = tmp; } else { data.fieldValue = ""; } } data.fieldValue = checkBackSlash(data.fieldValue, isFile); text.setText(data.fieldValue); // text.setSelection(text.getCharCount()); } if (isMultiline) { for (int i = 0; i < rows; i++) { Label dummyLabel = new Label(parent, SWT.NONE); dummyLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); // dummyLabel.setText(""); } } if (isFile) { final Button browseButton = new Button(parent, SWT.PUSH); browseButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); browseButton.setText("..."); browseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog fileDialog = new FileDialog(text.getShell(), isInFile ? SWT.OPEN : SWT.SAVE); String lastFolderChosen = OmsBoxPlugin.getDefault().getLastFolderChosen(); fileDialog.setFilterPath(lastFolderChosen); String path = fileDialog.open(); if (path == null || path.length() < 1) { text.setText(""); } else { path = checkBackSlash(path, isFile); text.setText(path); text.setSelection(text.getCharCount()); setDataValue(); } OmsBoxPlugin.getDefault().setLastFolderChosen(fileDialog.getFilterPath()); } }); } if (isFolder) { final Button browseButton = new Button(parent, SWT.PUSH); browseButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); browseButton.setText("..."); browseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog directoryDialog = new DirectoryDialog(text.getShell(), isInFolder ? SWT.OPEN : SWT.SAVE); String lastFolderChosen = OmsBoxPlugin.getDefault().getLastFolderChosen(); directoryDialog.setFilterPath(lastFolderChosen); String path = directoryDialog.open(); if (path == null || path.length() < 1) { text.setText(""); } else { path = checkBackSlash(path, isFile); text.setText(path); // text.setSelection(text.getCharCount()); setDataValue(); } OmsBoxPlugin.getDefault().setLastFolderChosen(directoryDialog.getFilterPath()); } }); } if (isCrs) { // the crs choice group final Button crsButton = new Button(parent, SWT.BORDER); crsButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); crsButton.setText("..."); //$NON-NLS-1$ crsButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { Shell shell = new Shell(text.getShell(), SWT.SHELL_TRIM); Dialog dialog = new Dialog(shell) { private CRSChooser chooser; private CoordinateReferenceSystem crs; @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("Choose CRS"); } @Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); GridLayout gLayout = (GridLayout) comp.getLayout(); gLayout.numColumns = 1; chooser = new CRSChooser(new Controller() { public void handleClose() { buttonPressed(OK); } public void handleOk() { buttonPressed(OK); } }); return chooser.createControl(parent); } @Override protected void buttonPressed(int buttonId) { if (buttonId == OK) { crs = chooser.getCRS(); try { String codeFromCrs = OmsBoxUtils.getCodeFromCrs(crs); text.setText(codeFromCrs); } catch (Exception e) { e.printStackTrace(); } } close(); } }; dialog.setBlockOnOpen(true); dialog.open(); } }); // initially set to map's crs IMap activeMap = ApplicationGIS.getActiveMap(); if (activeMap != null) { try { CoordinateReferenceSystem crs = activeMap.getViewportModel().getCRS(); String codeFromCrs = OmsBoxUtils.getCodeFromCrs(crs); text.setText(codeFromCrs); setDataValue(); } catch (Exception e) { e.printStackTrace(); } } } if (isNorthing || isEasting || isEastingNorthing) { addMapMouseListener(); } if (isProcessing()) { addRegionListener(); ILayer processingRegionLayer = OmsBoxPlugin.getDefault().getProcessingRegionMapGraphic(); IStyleBlackboard blackboard = processingRegionLayer.getStyleBlackboard(); Object object = blackboard.get(ProcessingRegionStyleContent.ID); if (object instanceof ProcessingRegionStyle) { ProcessingRegionStyle processingStyle = (ProcessingRegionStyle) object; setRegion(processingStyle); } } text.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (isNorthing || isEasting || isEastingNorthing) { removeMapMouseListener(); } if (isProcessing()) { removeRegionListener(); } } }); addDrop(); return text; }
From source file:org.locationtech.udig.ui.FeatureTypeEditorTest.java
License:Open Source License
@Before public void setUp() throws Exception { features = UDIGTestUtil.createDefaultTestFeatures(featureTypeName, 1); featureType = features[0].getFeatureType(); dialog = new Dialog(Display.getCurrent().getActiveShell()) { SimpleFeatureTypeBuilder builder = null; @Override// www . j a v a 2 s . c om protected Point getInitialSize() { return new Point(500, 500); } @Override protected Layout getLayout() { return new GridLayout(1, true); } @Override protected Control createDialogArea(Composite parent) { editor = new FeatureTypeEditor(); editor.createFeatureTypeNameText(parent, null); editor.createTable(parent, null, builder.buildFeatureType(), true); return editor.getControl(); } @Override public boolean close() { builder = editor.getFeatureTypeBuilder(); return super.close(); } }; try { editor.setFeatureType(featureType); fail("Should throw an exception if the feature type is set before table is created"); //$NON-NLS-1$ } catch (Exception e) { //proper behaviour. } dialog.setBlockOnOpen(false); dialog.open(); editor.setFeatureType(featureType); UDIGTestUtil.inDisplayThreadWait(1000, new WaitCondition() { public boolean isTrue() { return dialog.getShell().isVisible(); } }, true); }
From source file:org.rdkit.knime.wizards.RDKitNodesWizardsPage.java
License:Open Source License
/** * Shows the help dialog window.//from w w w . j av a2s . c o m */ public void showHelp() { // Copy help files to temp directory URL fileUrlTemp = null; try { fileUrlTemp = makeHelpFilesAvailable(); } catch (IOException exc) { // Ignored - handled later } final Shell parentShell = getShell(); if (fileUrlTemp != null) { final URL fileUrl = fileUrlTemp; Dialog dialog = new Dialog(parentShell) { @Override protected Control createDialogArea(final Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); Browser browser = new Browser(composite, SWT.BORDER | SWT.FILL); browser.setUrl(fileUrl.toString()); GridData data = new GridData(GridData.FILL_BOTH); browser.setLayoutData(data); return composite; } @Override protected void createButtonsForButtonBar(final Composite parent) { // create OK button createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); } @Override protected Point getInitialSize() { return new Point(700, 700); } @Override protected Point getInitialLocation(final Point initialSize) { Dimension dimScreen = Toolkit.getDefaultToolkit().getScreenSize(); return new Point(dimScreen.width / 2 - initialSize.x / 2, dimScreen.height / 2 - initialSize.y / 2); } @Override protected void configureShell(final Shell newShell) { super.configureShell(newShell); newShell.setText("RDKit Node Types"); } }; dialog.setBlockOnOpen(true); dialog.open(); // Blocks } else { MessageBox msgBox = new MessageBox(parentShell, SWT.ICON_ERROR | SWT.OK); msgBox.setText("Error"); msgBox.setMessage("Sorry. The help file is not available."); msgBox.open(); } }
From source file:org.talend.repository.ui.wizards.metadata.table.database.DatabaseTableFilterForm.java
License:Open Source License
/** * addButtonControls.//from w w w . j a v a2 s. c o m * */ @Override protected void addUtilsButtonListeners() { tableCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getTableInfoParameters().changeType(ETableTypes.TABLETYPE_TABLE, tableCheck.getSelection()); // Added by Marvin Wang on Feb. 5, 2012 for bug TDI-24413, in fact the type is added here is not a good // way. // Suggestion: We could abstract the TableInfoParameters as a reference in DatabaseTableWizardPage. Each // child like "HiveTableInfoParameters" could implement "getTypes()" to return the private types. When // types are reqired, it could invoke like // "DatabaseTableWizardPage.getTableInfoParameters().getTypes()". getTableInfoParameters().changeType(ETableTypes.TABLETYPE_EXTERNAL_TABLE, tableCheck.getSelection()); getTableInfoParameters().changeType(ETableTypes.EXTERNAL_TABLE, tableCheck.getSelection()); getTableInfoParameters().changeType(ETableTypes.MANAGED_TABLE, tableCheck.getSelection()); getTableInfoParameters().changeType(ETableTypes.INDEX_TABLE, tableCheck.getSelection()); } }); viewCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getTableInfoParameters().changeType(ETableTypes.TABLETYPE_VIEW, viewCheck.getSelection()); getTableInfoParameters().changeType(ETableTypes.VIRTUAL_VIEW, viewCheck.getSelection()); } }); synonymCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getTableInfoParameters().changeType(ETableTypes.TABLETYPE_SYNONYM, synonymCheck.getSelection()); } }); // hide for the bug 7959 if (isOracle()) { publicSynonymCheck.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getTableInfoParameters().changeType(ETableTypes.TABLETYPE_ALL_SYNONYM, publicSynonymCheck.getSelection()); ExtractMetaDataUtils.getInstance().setUseAllSynonyms(publicSynonymCheck.getSelection()); if (publicSynonymCheck.getSelection()) { tableCheck.setEnabled(false); viewCheck.setEnabled(false); synonymCheck.setEnabled(false); } else { tableCheck.setEnabled(true); viewCheck.setEnabled(true); synonymCheck.setEnabled(true); } } }); } SelectionAdapter selectionAdapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { addName = ""; //$NON-NLS-1$ Dialog dialog = new Dialog(getShell()) { Text addText; @Override protected Control createDialogArea(Composite parent) { Composite createDialogArea = (Composite) super.createDialogArea(parent); Label addLabel = new Label(createDialogArea, SWT.NONE); addLabel.setText(Messages.getString("DatabaseTableFilterForm.filterName")); //$NON-NLS-1$ addText = new Text(createDialogArea, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_BOTH); addText.setLayoutData(gridData); addText.setText(addName); return createDialogArea; } /* * (non-Javadoc) * * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("DatabaseTableFilterForm.newFilterName")); //$NON-NLS-1$ } /* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ @Override protected void okPressed() { addName = addText.getText(); super.okPressed(); } }; if (dialog.open() == Dialog.OK) { nameFilter.add(addName, 0); nameFilter.select(0); removeButton.setEnabled(true); editButton.setEnabled(true); } } }; newButton.addSelectionListener(selectionAdapter); selectionAdapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final int index = nameFilter.getSelectionIndex(); if (nameFilter.getSelection().length > 0) { addName = nameFilter.getSelection()[0]; } Dialog dialog = new Dialog(getShell()) { Text addText; @Override protected Control createDialogArea(Composite parent) { Composite createDialogArea = (Composite) super.createDialogArea(parent); Label addLabel = new Label(createDialogArea, SWT.NONE); addLabel.setText(Messages.getString("DatabaseTableFilterForm.filterName")); //$NON-NLS-1$ addText = new Text(createDialogArea, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_BOTH); addText.setLayoutData(gridData); addText.setText(addName); return createDialogArea; } /* * (non-Javadoc) * * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.getString("DatabaseTableFilterForm.editFilterName")); //$NON-NLS-1$ } /* * (non-Javadoc) * * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ @Override protected void okPressed() { addName = addText.getText(); super.okPressed(); } }; if (dialog.open() == Dialog.OK) { nameFilter.setItem(index, addName); nameFilter.select(index); } } }; editButton.addSelectionListener(selectionAdapter); selectionAdapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (nameFilter.getSelection().length > 0) { addName = nameFilter.getSelection()[0]; nameFilter.remove(addName); } } }; removeButton.addSelectionListener(selectionAdapter); }
From source file:org.testeditor.ui.uiscanner.ui.UiscannerHandler.java
License:Open Source License
/** * Starts the UiScanner in a new Window. * /*from www . j a va2 s . co m*/ * @param shell * Shell for the new Dialog * @param context * IEclipseContext */ @Execute public void execute(Shell shell, final IEclipseContext context) { Dialog dialog = new Dialog(shell) { private UIScannerViewer viewer; @Override protected org.eclipse.swt.widgets.Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); context.set(Composite.class, area); UiScannerTranslationService trans = ContextInjectionFactory.make(UiScannerTranslationService.class, context); context.set(UiScannerTranslationService.class, trans); viewer = ContextInjectionFactory.make(UIScannerViewer.class, context); return area; } @Override protected Point getInitialSize() { return new Point(1000, 750); } @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false); } @Override public boolean close() { viewer.closeBrowser(); return super.close(); } @Override protected boolean isResizable() { return true; } @Override protected void setShellStyle(int newShellStyle) { super.setShellStyle(SWT.MIN | SWT.MAX | SWT.MODELESS | SWT.BORDER | SWT.TITLE | SWT.RESIZE); setBlockOnOpen(false); } }; dialog.open(); }