List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:com.toedter.e4.demo.contacts.rap.views.DetailsView.java
License:Open Source License
@Inject public void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Contact contact) { if (contact != null) { if (dirtyable.isDirty()) { MessageDialog dialog = new MessageDialog(detailComposite.getShell(), "Save vCard", null, "The current vCard has been modified. Save changes?", MessageDialog.CONFIRM, new String[] { "Yes", "No" }, 0); dialog.create();//from ww w.ja va2 s . c om ThemeUtil.applyDialogStyles(engine, dialog.getShell()); if (dialog.open() == Window.OK) { ParameterizedCommand saveCommand = commandService.createCommand("contacts.save", Collections.EMPTY_MAP); handlerService.executeHandler(saveCommand); } } updatePartTitle(contact); } else { uiItem.setLabel("Details"); } dirtyable.setDirty(false); detailComposite.update(contact); }
From source file:com.toedter.e4.demo.contacts.swt.views.DetailsView.java
License:Open Source License
@Inject public void setSelection(@Optional Contact contact) { if (contact != null) { if (dirtyable.isDirty()) { MessageDialog dialog = new MessageDialog(detailComposite.getShell(), "Save vCard", null, "The current vCard has been modified. Save changes?", MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); dialog.create();/* w w w .java 2 s . c o m*/ if (engine != null) { ThemeUtil.applyDialogStyles(engine, dialog.getShell()); } if (dialog.open() == Window.OK) { ParameterizedCommand saveCommand = commandService.createCommand("contacts.save", Collections.EMPTY_MAP); handlerService.executeHandler(saveCommand); } } updatePartTitle(contact); } else { uiItem.setLabel("Details"); } dirtyable.setDirty(false); detailComposite.update(contact); }
From source file:com.toubassi.filebunker.ui.backup.BackupController.java
License:Open Source License
private void performBackup() { Shell shell = getShell();/* w w w.ja v a 2s . c o m*/ if (!vault.isConfigured()) { String[] buttons = new String[] { "Configure", "Cancel" }; MessageDialog dialog = new MessageDialog(shell, "Backup", null, "You cannot perform a backup until FileBunker has been " + "configured. You can select the Configure button " + "below or select Configuration from the File menu " + "at any time.", MessageDialog.INFORMATION, buttons, 0); int selectedButton = dialog.open(); if (selectedButton == 0) { configurationAction.run(); } return; } BackupResult result = new BackupResult(); PerformBackup performBackup = new PerformBackup(vault, backupSpec, result, false); try { new ProgressMonitorDialog(shell).run(true, true, performBackup); String message; if (result.numberOfFiles() == 0) { message = "No files are in need of backup."; } else { message = formatBackupResultMessage(result, performBackup.estimate(), false); } MessageDialog.openInformation(shell, "Backup Complete", message); } catch (InvocationTargetException e) { handleBackupException(e, result, performBackup.estimate()); } catch (InterruptedException e) { handleBackupException(e, result, performBackup.estimate()); } }
From source file:com.toubassi.filebunker.ui.FileBunker.java
License:Open Source License
/** * We require 1.4.2_05 or later due to our dependence on https. Make sure * we are running against that VM, or a later one. * /*from ww w . j av a 2 s . c om*/ * @param shell */ private void verifyJavaRuntimeVersion(Shell shell) { String version = System.getProperty("java.runtime.version"); // Skip any leading text like "Blackdown" (see // http://sourceforge.net/tracker/index.php?func=detail&aid=1181135&group_id=118802&atid=682209 for (int i = 0, count = version.length(); i < count; i++) { char ch = version.charAt(i); if (Character.isDigit(ch)) { version = version.substring(i); break; } } StringTokenizer tokenizer = new StringTokenizer(version, "._-"); boolean ok = false; try { if (tokenizer.hasMoreTokens()) { String major = tokenizer.nextToken(); if (Integer.parseInt(major) > 2) { ok = true; } } if (!ok && tokenizer.hasMoreTokens()) { String minor = tokenizer.nextToken(); if (Integer.parseInt(minor) > 4) { ok = true; } } if (!ok && tokenizer.hasMoreTokens()) { String patch = tokenizer.nextToken(); if (Integer.parseInt(patch) > 2) { ok = true; } } if (!ok && tokenizer.hasMoreTokens()) { String subpatch = tokenizer.nextToken(); if (Integer.parseInt(subpatch) >= 5) { ok = true; } } } catch (NumberFormatException e) { Log.log(e, "Exception parsing runtime version: '" + version + "'"); throw e; } if (!ok) { String[] buttons = new String[] { "Quit", "Continue" }; String message = "FileBunker requires Java Runtime version 1.4.2_05 or later. " + "You are currently running " + version + ". If you continue, " + "the application is unlikely to function properly. It is " + "strongly recommended that you quit and install a more recent " + "Java Runtime."; MessageDialog dialog = new MessageDialog(shell, "Error", shell.getDisplay().getSystemImage(SWT.ICON_ERROR), message, MessageDialog.ERROR, buttons, 0); if (dialog.open() == 0) { System.exit(0); } } }
From source file:com.toubassi.filebunker.ui.restore.RestoreController.java
License:Open Source License
public void restore(RestoreSpecification restoreSpec) { Shell shell = getShell();/*from w w w. j a v a 2 s . c om*/ if (!vault.isConfigured()) { String[] buttons = new String[] { "Configure", "Cancel" }; MessageDialog dialog = new MessageDialog(shell, "Backup", null, "You cannot restore files until FileBunker has been " + "configured. You can select the Configure button " + "below or select Configuration from the File menu " + "at any time.", MessageDialog.INFORMATION, buttons, 0); int selectedButton = dialog.open(); if (selectedButton == 0) { configurationAction.run(); } return; } String restorePath; ArrayList revisions = restoreSpec.revisions(); boolean singleFileSelected = revisions.size() == 1 && !((Revision) revisions.get(0)).isDirectory(); if (singleFileSelected) { FileRevision revision = (FileRevision) revisions.get(0); File proposedFile = proposedFileRestoreLocation(revision.node().file()); FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setFilterPath(proposedFile.getParent()); dialog.setFileName(proposedFile.getName()); restorePath = dialog.open(); } else { DirectoryDialog dialog = new DirectoryDialog(getShell()); if (revisions.size() == 1) { dialog.setMessage("Choose the name that the selected folder " + "will be restored as. For files that already exist " + "on disk, unique names will be used so that no " + "files are overwritten."); } else { dialog.setMessage("Choose the folder into which the selected files " + "will be restored. For files that already exist " + "on disk, unique names will be used so that no " + "files are overwritten."); } dialog.setFilterPath(spec.commonPath()); restorePath = dialog.open(); } if (restorePath == null) { return; } File restoreRoot = new File(restorePath); if (singleFileSelected && restoreRoot.exists()) { MessageBox dialog = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO); dialog.setMessage(restoreRoot.getName() + " already exists. Do you want to replace it?"); if (dialog.open() != SWT.YES) { return; } } RestoreResult result = new RestoreResult(); PerformRestore performRestore = new PerformRestore(vault, restoreSpec, restoreRoot, result); try { new ProgressMonitorDialog(shell).run(true, true, performRestore); String message; if (result.numberOfFiles() == 0) { message = "No files were restored."; } else { message = formatRestoreResultMessage(result, performRestore.estimate(), false); } MessageDialog.openInformation(shell, "Restore Complete", message); } catch (InvocationTargetException e) { handleException(e, restoreSpec, result, performRestore.estimate()); } catch (InterruptedException e) { handleException(e, restoreSpec, result, performRestore.estimate()); } }
From source file:com.twinsoft.convertigo.eclipse.dialogs.MultipleDeletionDialog.java
License:Open Source License
private boolean confirmOverwrite(String msg) { if (shell == null) return false; final MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0); shell.getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); }//from w w w . j a v a 2 s. co m }); if (hasMultiple) { switch (dialog.getReturnCode()) { case 0: return true; case 1: confirmation = YES_TO_ALL; return true; case 2: return false; case 3: confirmation = NO_TO_ALL; default: return false; } } else { switch (dialog.getReturnCode()) { case 0: return true; case 1: return false; case 2: default: return false; } } }
From source file:com.ultimatetech.cim.views.CIMInstanceView.java
License:Open Source License
private void makeActions() { setInstanceAct = new Action() { public void run() { //get client CIMClient client = null;// w w w .j a v a 2 s.c o m try { client = CIMConnect.connectUsingPreferences(); try { client.setInstance(cimInstance.getObjectPath(), cimInstance, false, (String[]) changedProps.toArray(new String[] {})); showMessage("Set instance successfull"); setInstanceAct.setEnabled(false); } catch (CIMException e) { e.printStackTrace(); ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Set Instance Error", "Set Instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } } finally { if (client != null) { try { client.close(); } catch (CIMException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }; setInstanceAct.setText("Set instance"); setInstanceAct.setToolTipText("Set instance"); setInstanceAct.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/save.gif")); setInstanceAct.setDisabledImageDescriptor(CIMPlugin.getImageDescriptor("icons/save_disabled.gif")); setInstanceAct.setEnabled(false); deleteInstance = new Action() { public void run() { CIMClient client = CIMConnect.connectUsingPreferences(); try { MessageDialog areYouSure = new MessageDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance?", MessageDialog.getImage(MessageDialog.DLG_IMG_QUESTION), "Delete this instance?", MessageDialog.QUESTION, new String[] { "OK", "Cancel" }, 0); areYouSure.open(); if (areYouSure.getReturnCode() == MessageDialog.OK) { client.deleteInstance(cimInstance.getObjectPath()); clearView(); CIMExplorerView cev = (CIMExplorerView) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().showView("com.ultimatetech.cim.views.CIMExplorerView"); cev.refreshAllTreeNodes(); } } catch (CIMException e) { ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance Error", "Delete instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } catch (Exception e) { ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance Error", "Delete instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", 100, e.getMessage(), e), IStatus.ERROR); ed.open(); } finally { if (client != null) { try { client.close(); } catch (CIMException e) { e.printStackTrace(); } } } //showMessage("Delete instance not yet implemented"); } }; deleteInstance.setText("Delete instance"); deleteInstance.setToolTipText("Delete instance"); deleteInstance.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK)); /*doubleClickAction = new Action() { public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection)selection).getFirstElement(); showMessage("Double-click detected on "+obj.toString()); } };*/ refreshAction = new Action() { public void run() { CIMClient client = CIMConnect.connectUsingPreferences(); try { cimInstance = client.getInstance(cimInstance.getObjectPath(), false, true, true, null); showMessage("Instance reloaded"); } catch (CIMException e) { e.printStackTrace(); ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Reload Instance Error", "Reload Instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } finally { if (client != null) { try { client.close(); } catch (CIMException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } setInstanceAct.setEnabled(false); } }; refreshAction.setText("Reload instance"); refreshAction.setToolTipText("Reload instance"); refreshAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_REDO)); }
From source file:com.vectrace.MercurialEclipse.dialogs.CommitDialog.java
License:Open Source License
private boolean confirmHistoryRewrite() { if (HgFeatures.PHASES.isEnabled()) { // For secret or draft silently allow amend if (Phase.PUBLIC == currentChangeset.getPhase()) { if (!MessageDialog.openConfirm(getShell(), Messages.getString("CommitDialog.amendPublic.title"), Messages.getString("CommitDialog.amendPublic.message"))) { return false; }//w ww . j av a2 s . c o m currentChangeset.setDraft(); } return true; } // Always prompt if phases are not supported MessageDialog dialog = new MessageDialog(getShell(), Messages.getString("CommitDialog.reallyAmendAndRewriteHistory"), //$NON-NLS-1$ null, Messages.getString("CommitDialog.amendWarning1") //$NON-NLS-1$ + Messages.getString("CommitDialog.amendWarning2") //$NON-NLS-1$ + Messages.getString("CommitDialog.amendWarning3"), //$NON-NLS-1$ MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 1 // default index - cancel ); dialog.setBlockOnOpen(true); // if false then may show in background return dialog.open() == 0; // 0 means yes }
From source file:com.vectrace.MercurialEclipse.menu.RebaseHandler.java
License:Open Source License
public static void openWizard(HgRoot hgRoot, Shell shell) throws CoreException { if (HgRebaseClient.isRebasing(hgRoot)) { MessageDialog dialog = new MessageDialog(null, Messages.getString("RebaseHandler.inProgress"), null, Messages.getString("RebaseHandler.inProgressAbortOrContinue"), MessageDialog.QUESTION, new String[] { Messages.getString("RebaseHandler.cancel"), Messages.getString("RebaseHandler.abort"), Messages.getString("RebaseHandler.continue") }, 2);//from w ww . j av a 2 s . c o m switch (dialog.open()) { case 1: // Shouldn't fail HgRebaseClient.abortRebase(hgRoot); break; case 2: ContinueRebaseHandler handler = new ContinueRebaseHandler(); handler.setShell(shell); handler.run(hgRoot); break; } } else { RebaseWizard wizard = new RebaseWizard(hgRoot); WizardDialog wizardDialog = new WizardDialog(shell, wizard); wizardDialog.open(); } }
From source file:com.vectrace.MercurialEclipse.menu.ShelveHandler.java
License:Open Source License
@Override protected void run(final HgRoot hgRoot) { new SafeWorkspaceJob(Messages.getString("ShelveHandler.Shelving")) { //$NON-NLS-1$ @Override/*w w w .j ava2s .c om*/ protected IStatus runSafe(IProgressMonitor monitor) { final ShelveOperation op = new ShelveOperation((IWorkbenchPart) null, hgRoot, false); try { op.run(monitor); return super.runSafe(monitor); } catch (InvocationTargetException e) { if (op.getShelveFileConflict() != null) { getShell().getDisplay().asyncExec(new Runnable() { public void run() { MessageDialog dialog = new MessageDialog(getShell(), "Shelve file exists. Delete shelved changes?", null, "Shelve file exists. You must unshelve before shelving anew. " + "Would you like to delete shelved changes instead?", MessageDialog.QUESTION, new String[] { "Delete shelved changes", "Retain" }, 1) { { setShellStyle(getShellStyle() | SWT.SHEET); } }; if (dialog.open() == 0) { op.getShelveFileConflict().delete(); ShelveHandler.this.run(hgRoot); } } }); return Status.OK_STATUS; } return new Status(IStatus.WARNING, MercurialEclipsePlugin.ID, 0, e.getLocalizedMessage(), e); } catch (InterruptedException e) { return new Status(IStatus.INFO, MercurialEclipsePlugin.ID, 0, e.getLocalizedMessage(), e); } } }.schedule(); }