List of usage examples for org.eclipse.jface.window Window CANCEL
int CANCEL
To view the source code for org.eclipse.jface.window Window CANCEL.
Click Source Link
From source file:ac.soton.eventb.classdiagrams.diagram.part.ClassdiagramsDiagramEditor.java
License:Open Source License
/** * @generated/*from ww w. ja v a2 s .c o m*/ */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); IEditorInput input = getEditorInput(); SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; if (original != null) { dialog.setOriginalFile(original); } dialog.create(); IDocumentProvider provider = getDocumentProvider(); if (provider == null) { // editor has been programmatically closed while the dialog was open return; } if (provider.isDeleted(input) && original != null) { String message = NLS.bind(Messages.ClassdiagramsDiagramEditor_SavingDeletedFile, original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IPath filePath = dialog.getResult(); if (filePath == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(filePath); final IEditorInput newInput = new FileEditorInput(file); // Check if the editor is already open IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy(); IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { if (matchingStrategy.matches(editorRefs[i], newInput)) { MessageDialog.openWarning(shell, Messages.ClassdiagramsDiagramEditor_SaveAsErrorTitle, Messages.ClassdiagramsDiagramEditor_SaveAsErrorMessage); return; } } boolean success = false; try { provider.aboutToChange(newInput); getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { ErrorDialog.openError(shell, Messages.ClassdiagramsDiagramEditor_SaveErrorTitle, Messages.ClassdiagramsDiagramEditor_SaveErrorMessage, x.getStatus()); } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } }
From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractTablePropertySection.java
License:Open Source License
protected Object[] getNewReferences() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new BLabelProvider()); dialog.setFilter(null);//from ww w. j av a2 s. co m dialog.setElements(getPossibleChildren().toArray()); dialog.setTitle(getNewChildrenDialogTitle()); dialog.create(); dialog.open(); if (dialog.getReturnCode() == Window.CANCEL) return null; return dialog.getResult(); }
From source file:ac.soton.eventb.statemachines.diagram.part.StatemachinesDiagramEditor.java
License:Open Source License
/** * @generated/*from w w w.j a v a2 s . c om*/ */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); IEditorInput input = getEditorInput(); SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; if (original != null) { dialog.setOriginalFile(original); } dialog.create(); IDocumentProvider provider = getDocumentProvider(); if (provider == null) { // editor has been programmatically closed while the dialog was open return; } if (provider.isDeleted(input) && original != null) { String message = NLS.bind(Messages.StatemachinesDiagramEditor_SavingDeletedFile, original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IPath filePath = dialog.getResult(); if (filePath == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(filePath); final IEditorInput newInput = new FileEditorInput(file); // Check if the editor is already open IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy(); IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { if (matchingStrategy.matches(editorRefs[i], newInput)) { MessageDialog.openWarning(shell, Messages.StatemachinesDiagramEditor_SaveAsErrorTitle, Messages.StatemachinesDiagramEditor_SaveAsErrorMessage); return; } } boolean success = false; try { provider.aboutToChange(newInput); getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { ErrorDialog.openError(shell, Messages.StatemachinesDiagramEditor_SaveErrorTitle, Messages.StatemachinesDiagramEditor_SaveErrorMessage, x.getStatus()); } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } }
From source file:ac.soton.fmusim.components.diagram.part.ComponentsDiagramEditor.java
License:Open Source License
/** * @generated//from w w w .java2 s . c om */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); IEditorInput input = getEditorInput(); SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; if (original != null) { dialog.setOriginalFile(original); } dialog.create(); IDocumentProvider provider = getDocumentProvider(); if (provider == null) { // editor has been programmatically closed while the dialog was open return; } if (provider.isDeleted(input) && original != null) { String message = NLS.bind(Messages.ComponentsDiagramEditor_SavingDeletedFile, original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IPath filePath = dialog.getResult(); if (filePath == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(filePath); final IEditorInput newInput = new FileEditorInput(file); // Check if the editor is already open IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy(); IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { if (matchingStrategy.matches(editorRefs[i], newInput)) { MessageDialog.openWarning(shell, Messages.ComponentsDiagramEditor_SaveAsErrorTitle, Messages.ComponentsDiagramEditor_SaveAsErrorMessage); return; } } boolean success = false; try { provider.aboutToChange(newInput); getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { ErrorDialog.openError(shell, Messages.ComponentsDiagramEditor_SaveErrorTitle, Messages.ComponentsDiagramEditor_SaveErrorMessage, x.getStatus()); } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } }
From source file:ac.soton.multisim.diagram.part.MultisimDiagramEditor.java
License:Open Source License
/** * @generated/* ww w .j av a 2 s.c om*/ */ protected void performSaveAs(IProgressMonitor progressMonitor) { Shell shell = getSite().getShell(); IEditorInput input = getEditorInput(); SaveAsDialog dialog = new SaveAsDialog(shell); IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; if (original != null) { dialog.setOriginalFile(original); } dialog.create(); IDocumentProvider provider = getDocumentProvider(); if (provider == null) { // editor has been programmatically closed while the dialog was open return; } if (provider.isDeleted(input) && original != null) { String message = NLS.bind(Messages.MultisimDiagramEditor_SavingDeletedFile, original.getName()); dialog.setErrorMessage(null); dialog.setMessage(message, IMessageProvider.WARNING); } if (dialog.open() == Window.CANCEL) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IPath filePath = dialog.getResult(); if (filePath == null) { if (progressMonitor != null) { progressMonitor.setCanceled(true); } return; } IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile file = workspaceRoot.getFile(filePath); final IEditorInput newInput = new FileEditorInput(file); // Check if the editor is already open IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy(); IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getEditorReferences(); for (int i = 0; i < editorRefs.length; i++) { if (matchingStrategy.matches(editorRefs[i], newInput)) { MessageDialog.openWarning(shell, Messages.MultisimDiagramEditor_SaveAsErrorTitle, Messages.MultisimDiagramEditor_SaveAsErrorMessage); return; } } boolean success = false; try { provider.aboutToChange(newInput); getDocumentProvider(newInput).saveDocument(progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true); success = true; } catch (CoreException x) { IStatus status = x.getStatus(); if (status == null || status.getSeverity() != IStatus.CANCEL) { ErrorDialog.openError(shell, Messages.MultisimDiagramEditor_SaveErrorTitle, Messages.MultisimDiagramEditor_SaveErrorMessage, x.getStatus()); } } finally { provider.changed(newInput); if (success) { setInput(newInput); } } if (progressMonitor != null) { progressMonitor.setCanceled(!success); } }
From source file:ag.ion.noa4e.ui.NOAUIPlugin.java
License:Open Source License
/** * Starts local office application./*from w ww . j a v a 2 s . c o m*/ * * @param shell shell to be used * @param officeApplication office application to be started * * @return information whether the office application was started or not - only * if the status severity is <code>IStatus.OK</code> the application was started * * @author Joerg Sigle * @date 24.06.2012 * @date 20.02.2012 * * @author Andreas Brker * @date 28.06.2006 */ public static IStatus startLocalOfficeApplication(Shell shell, IOfficeApplication officeApplication) { System.out.println("NOAUIPlugin: startLocalOfficeApplication(Shell, officeApplication) begin"); while (true) { System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): while (true) trying to start..."); IStatus status = internalStartApplication(shell, officeApplication); System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): returned from trying to start."); if (status == null) System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): status==null"); else System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): status=" + status.toString()); if (status.getSeverity() == IStatus.ERROR) { System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): WARNING: status.getSeverity()==IStatus.ERROR"); if (MessageDialog.openQuestion(shell, Messages.NOAUIPlugin_dialog_change_preferences_title, Messages.NOAUIPlugin_dialog_change_preferences_message)) { PreferenceDialog preferenceDialog = PreferencesUtil.createPreferenceDialogOn(shell, LocalOfficeApplicationPreferencesPage.PAGE_ID, null, null); if (preferenceDialog.open() == Window.CANCEL) return Status.CANCEL_STATUS; else continue; } } else System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): SUCCESS: !status.getSeverity()==IStatus.ERROR"); try { //My warning in the following line referred to the original noa4e code: //System.out.println("NOAUIPlugin: internalStartApplication(2): getting officeHome (WARNING: probably from the wrong source)..."); System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): getting officeHome..."); System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): Using js mod adopted for Elexis, reproducing prior GW adoptions, P_OOBASEDIR via ...(Hub.localCfg)"); //JS modified this: //The original code tries to access a preference store which is not used in Elexis, //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java //Unsuitable original line, removed: //String officeHome = getDefault().getPreferenceStore().getString(PREFERENCE_OFFICE_HOME); //Newly inserted lines: IPreferenceStore preferenceStore = new SettingsPreferenceStore(CoreHub.localCfg); String officeHome = preferenceStore.getString(PreferenceConstants.P_OOBASEDIR); if (officeHome == null) System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): WARNING: officeHome==null"); else System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): officeHome=" + officeHome); System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): trying to get preventTermination setting..."); //My warning in the following line referred to the original noa4e code: //System.out.println("NOAUIPlugin: WARNING: THIS PROBABLY REFERENCES THE WRONG PREFERENCE STORE. SEE LocalPreferences...GWeirich/JS mods"); //JS modified this: //The original code tries to access a preference store which is not used in Elexis, //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java //Unsuitable original line, removed: //boolean preventTermination = getDefault().getPreferenceStore().getBoolean(PREFERENCE_PREVENT_TERMINATION); //Newly inserted lines: //Already declared further above: IPreferenceStore preferenceStore = new SettingsPreferenceStore(Hub.localCfg); boolean preventTermination = preferenceStore.getBoolean(PREFS_PREVENT_TERMINATION); System.out.println("NOAUIPlugin: startLocalOfficeApplication(2): got preventTermination setting=" + preventTermination); if (preventTermination) { System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): trying officeApplication.getDesktopService().activateTerminationPrevention()..."); officeApplication.getDesktopService().activateTerminationPrevention(); System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): SUCCESS: officeApplication.getDesktopService().activateTerminationPrevention()"); } } catch (OfficeApplicationException officeApplicationException) { //no prevention System.out.println( "NOAUIPlugin: startLocalOfficeApplication(2): FAILED: preventTermination could NOT be set."); } System.out.println("NOAUIPlugin: startLocalOfficeApplication(2) end, returning status"); return status; } }
From source file:ag.ion.noa4e.ui.NOAUIPlugin.java
License:Open Source License
/** * Internal method in order to start the office application. * /*from w w w. j a v a2 s . com*/ * @param shell shell to be used * @param officeApplication office application to be used * * @return status information * * @author Joerg Sigle * @date 24.06.2012 * @date 20.02.2012 00:57 * * @author Andreas Brker * @date 28.06.2006 * * Adopted for Elexis by Joerg Sigle 02/2012, adding the following line. * Changes required because of different preference store layout in Elexis. * There are corresponding changes in: * LocalOfficeApplicationsPreferencesPage.java * PREFS_PREVENT_TERMINATION * initPreferenceValues() * performOk() * NOAUIPlugin.java * PREFERENCE_OFFICE_HOME * PREFERENCE_PREVENT_TERMINATION * internalStartApplication(). */ private static IStatus internalStartApplication(final Shell shell, IOfficeApplication officeApplication) { System.out.println("NOAUIPlugin: internalStartApplication() begin"); if (officeApplication.isActive()) { System.out.println( "NOAUIPlugin: internalStartApplication(): officeApplication.isActive(), so returning immediately."); return Status.OK_STATUS; } System.out.println( "NOAUIPlugin: internalStartApplication(): !officeApplication.isActive(), so starting it up..."); boolean configurationChanged = false; boolean canStart = false; String home = null; HashMap configuration = new HashMap(1); //My warning in the following line referred to the original noa4e code: //System.out.println("NOAUIPlugin: internalStartApplication(): getting officeHome (WARNING: probably from the wrong source)..."); System.out.println("NOAUIPlugin: internalStartApplication(): getting officeHome..."); System.out.println( "NOAUIPlugin: internalStartApplication(): Using js mod adopted for Elexis, reproducing prior GW adoptions, P_OOBASEDIR via ...(Hub.localCfg)"); //JS modified this: //The original code tries to access a preference store which is not used in Elexis, //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java //Unsuitable original line, removed: //String officeHome = getDefault().getPreferenceStore().getString(PREFERENCE_OFFICE_HOME); //Newly inserted lines: IPreferenceStore preferenceStore = new SettingsPreferenceStore(CoreHub.localCfg); String officeHome = preferenceStore.getString(PreferenceConstants.P_OOBASEDIR); if (officeHome == null) System.out.println("NOAUIPlugin: internalStartApplication(): WARNING: officeHome==null"); else System.out.println("NOAUIPlugin: internalStartApplication(): officeHome=" + officeHome); if (officeHome.length() != 0) { File file = new File(officeHome); if (file.canRead()) { System.out.println( "NOAUIPlugin: internalStartApplication(): Check: officeHome is a valid path. Setting canStart to true."); configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, officeHome); canStart = true; } else { System.out.println( "NOAUIPlugin: internalStartApplication(): WARNING: officeHome is NOT a valid path. Leaving canStart at false."); MessageDialog.openWarning(shell, Messages.NOAUIPlugin_dialog_warning_invalid_path_title, Messages.NOAUIPlugin_dialog_warning_invalid_path_message); } } System.out.println("NOAUIPlugin: internalStartApplication(): canStart=" + canStart); if (!canStart) { System.out.println( "NOAUIPlugin: internalStartApplication(): canStart==false; trying to auto locate available office suite installations..."); configurationChanged = true; ILazyApplicationInfo[] applicationInfos = null; boolean configurationCompleted = false; try { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell); FindApplicationInfosOperation findApplicationInfosOperation = new FindApplicationInfosOperation(); progressMonitorDialog.run(true, true, findApplicationInfosOperation); applicationInfos = findApplicationInfosOperation.getApplicationsInfos(); if (applicationInfos.length == 1) { if (applicationInfos[0].getMajorVersion() == 2 || (applicationInfos[0].getMajorVersion() == 1 && applicationInfos[0].getMinorVersion() == 9)) { configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, applicationInfos[0].getHome()); configurationCompleted = true; } } } catch (Throwable throwable) { System.out.println( "NOAUIPlugin: internalStartApplication(): canStart==false; cannot auto locate an office suite installation. So we must search manually..."); //we must search manually } System.out.println( "NOAUIPlugin: internalStartApplication(): configurationCompleted=" + configurationCompleted); if (!configurationCompleted) { LocalApplicationWizard localApplicationWizard = new LocalApplicationWizard(applicationInfos); if (home != null && home.length() != 0) localApplicationWizard.setHomePath(home); WizardDialog wizardDialog = new WizardDialog(shell, localApplicationWizard); if (wizardDialog.open() == Window.CANCEL) return Status.CANCEL_STATUS; configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, localApplicationWizard.getSelectedHomePath()); } } System.out.println( "NOAUIPlugin: internalStartApplication(): the office suite configuration should now be valid:"); if (officeApplication == null) System.out.println("NOAUIPlugin: internalStartApplication(): officeApplication==null"); else System.out.println( "NOAUIPlugin: internalStartApplication(): officeApplication=" + officeApplication.toString()); if (configuration == null) System.out.println("NOAUIPlugin: internalStartApplication(): configuration==null"); else System.out .println("NOAUIPlugin: internalStartApplication(): configuration=" + configuration.toString()); if (shell == null) System.out.println("NOAUIPlugin: internalStartApplication(): shell==null"); else System.out.println("NOAUIPlugin: internalStartApplication(): shell=" + shell.toString()); System.out.println( "NOAUIPlugin: internalStartApplication(): Finally trying activateOfficeApplication(officeApplication, configuration, shell):"); IStatus status = activateOfficeApplication(officeApplication, configuration, shell); if (configurationChanged) { System.out.println( "NOAUIPlugin: internalStartApplication(): Configuration of PREFERENCE_OFFICE_HOME changed."); System.out.println("NOAUIPlugin: internalStartApplication(): Storing the new configuration."); System.out.println( "NOAUIPlugin: internalStartApplication(): Using js mod adopted for Elexis, reproducing prior GW adoptions, P_OOBASEDIR via ...(Hub.localCfg)"); //JS modified this: //The original code tries to access a preference store which is not used in Elexis, //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java //Unsuitable original line, removed: //getDefault().getPluginPreferences().setValue(PREFERENCE_OFFICE_HOME, // configuration.get(IOfficeApplication.APPLICATION_HOME_KEY).toString()); //Newly inserted line: preferenceStore.setValue(PreferenceConstants.P_OOBASEDIR, configuration.get(IOfficeApplication.APPLICATION_HOME_KEY).toString()); } System.out.println("NOAUIPlugin: internalStartApplication() end, returning status"); return status; }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.JFXBuildConfigurationEditor.java
License:Open Source License
private String handleRootclassSelection(Shell parent) { IFileEditorInput i = (IFileEditorInput) getEditorInput(); IJavaProject project = JavaCore.create(i.getFile().getProject()); if (project == null) { return null; }/* w ww .j a v a 2s .c om*/ IJavaElement[] elements = new IJavaElement[] { project }; int constraints = IJavaSearchScope.SOURCES; constraints |= IJavaSearchScope.APPLICATION_LIBRARIES; IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(elements, constraints); BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext(); MainTypeSelectionDialog dialog = new MainTypeSelectionDialog(parent, context, searchScope, 0); dialog.setTitle("Find class"); dialog.setMessage("Find the class used to launch the application"); if (dialog.open() == Window.CANCEL) { return null; } Object[] results = dialog.getResult(); IType type = (IType) results[0]; if (type != null) { return type.getFullyQualifiedName(); } return null; }
From source file:at.rc.tacos.client.ui.custom.DatePicker.java
License:Open Source License
private void initialize(int style) { GridLayout gridLayout = new GridLayout(2, false); gridLayout.horizontalSpacing = 0;/* w w w . ja va 2s. co m*/ gridLayout.verticalSpacing = 0; gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; this.setLayout(gridLayout); dateText = new Text(this, style); GridData dateTextGridData = new GridData(SWT.FILL, SWT.FILL, false, false); dateTextGridData.widthHint = 135; dateTextGridData.verticalIndent = 0; dateText.setLayoutData(dateTextGridData); dateText.setText(initialText); dateText.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // key listener used because setting of date picker text causes // modify listener to fire which results in perpetual dirty // editor notifyPickerListeners(); } }); dateText.addFocusListener(new FocusAdapter() { Calendar calendar = Calendar.getInstance(); @Override public void focusLost(FocusEvent e) { Date reminderDate; try { reminderDate = simpleDateFormat.parse(dateText.getText()); calendar.setTime(reminderDate); date = calendar; updateDateText(); } catch (ParseException e1) { updateDateText(); } } }); pickButton = new Button(this, style | SWT.ARROW | SWT.DOWN); GridData pickButtonGridData = new GridData(SWT.RIGHT, SWT.FILL, false, true); pickButtonGridData.verticalIndent = 0; pickButton.setLayoutData(pickButtonGridData); pickButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { Calendar newCalendar = Calendar.getInstance(); newCalendar.set(Calendar.HOUR_OF_DAY, 0); newCalendar.set(Calendar.MINUTE, 0); newCalendar.set(Calendar.SECOND, 0); newCalendar.set(Calendar.MILLISECOND, 0); if (date != null) { newCalendar.setTime(date.getTime()); } Shell shell = null; if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) { shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); } else { shell = new Shell(PlatformUI.getWorkbench().getDisplay()); } DateSelectionDialog dialog = new DateSelectionDialog(shell, newCalendar, DatePicker.TITLE_DIALOG); pickButton.setEnabled(false); dateText.setEnabled(false); int dialogResponse = dialog.open(); if (dialog.getDate() != null) newCalendar.setTime(dialog.getDate()); else newCalendar = null; dateSelected(dialogResponse == Window.CANCEL, newCalendar); } }); pack(); }
From source file:au.com.cybersearch2.controls.CustomDialog.java
License:Open Source License
/** * Open dialog synchronously in UI thread * @param sync UISynchronize object//from w w w .ja v a 2s . c o m * @return the return code */ public int syncOpen(UISynchronize sync) { final int[] returnCode = new int[] { Window.CANCEL }; sync.syncExec(new Runnable() { @Override public void run() { returnCode[0] = dialogBase.open(); } }); return returnCode[0]; }