List of usage examples for org.eclipse.jface.dialogs MessageDialog MessageDialog
public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels)
From source file:com.mindquarry.desktop.client.MindClient.java
License:Open Source License
private void ensureSettingsFolderExists() { File file = new File(PreferenceUtilities.SETTINGS_FOLDER); if (!file.exists()) { if (!file.mkdirs()) { log.error("Cannot create settings folder '" + file.getAbsolutePath() + "'"); MessageDialog dlg = new MessageDialog(getShell(), I18N.getString("Cannot create settings folder"), null,/* w w w . ja v a 2s . c o m*/ I18N.get("The Mindquarry Desktop Client cannot create its settings folder at\n\n" + "'{0}'\n\nMaybe you don't have permissions to access it?\n\n" + "If you continue, the program won't work properly, so it is strongly " + "recommended to ensure write-access to that folder and restart the client.", file.getAbsolutePath()), MessageDialog.ERROR, new String[] { I18N.getString("Exit"), I18N.getString("Start anyway") }, 0); int result = dlg.open(); if (result == 0) { System.exit(1); } else { log.warn("Starting despite missing settings folder"); //$NON-NLS-1$ } } } }
From source file:com.mindquarry.desktop.client.MindClient.java
License:Open Source License
private void createLock() { File f = new File(LOCK_FILE); try {//w w w . j av a 2 s . c o m if (!f.exists()) { f.createNewFile(); } } catch (IOException e) { log.error("Cannot create lock file '" + f.getAbsolutePath() + "'", e); //$NON-NLS-1$ } // this is the recommended way to implement locking, it doesn't leave // a lock file, not even if the app crashes: FileChannel fileChannel; try { fileChannel = (new FileOutputStream(f)).getChannel(); fileLock = fileChannel.tryLock(); if (fileLock == null) { MessageDialog dlg = new MessageDialog(getShell(), I18N.getString("Mindquarry Client already running"), null, I18N.getString("The Mindquarry Desktop Client seems to be running " + "already. Only one instance of the Desktop Client can be " + "running at a time. If you are sure that the Desktop Client " + "isn't running, select 'Start anyway'."), MessageDialog.ERROR, new String[] { I18N.getString("Exit"), I18N.getString("Start anyway") }, 0); int result = dlg.open(); if (result == 0) { System.exit(1); } else { log.warn("Starting despite lock file"); //$NON-NLS-1$ } } else { log.info("Aquired lock: " + fileLock); } } catch (IOException e) { log.error("Cannot create lock on lock file '" + f.getAbsolutePath(), e); } // Note: no need to delete the lock, the JVM will care about that }
From source file:com.mindquarry.desktop.client.MindClient.java
License:Open Source License
/** * Displays an error message and prompts the user to check their credentials * in the preferences dialog, or to cancel. * //from w w w .jav a 2 s . c o m * @param exception * Contains the error message to be displayed. * @return True if and only if preferences dialog was shown to user which * means that the credentials were potentially updated. */ public boolean handleNotAuthorizedException(NotAuthorizedException exception) { // create custom error message with the option to open the preferences // dialog MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$ null, (exception.getLocalizedMessage() + "\n\n" //$NON-NLS-1$ + I18N.getString( "Please check your username and password settings in the preferences dialog.")), //$NON-NLS-1$ MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$ I18N.getString("Cancel") //$NON-NLS-1$ }, 0); int buttonClicked = messageDialog.open(); switch (buttonClicked) { case 0: // go to preferences showPreferenceDialog(true); return true; case 1: // cancel displayNotConnected(); return false; } return false; }
From source file:com.mindquarry.desktop.client.MindClient.java
License:Open Source License
/** * Displays an error message and prompts the user to check their server * settings in the preferences dialog, or to cancel. * //from w ww .j a v a2 s. c o m * @param exception * Contains the unknown host. * @return True if and only if preferences dialog was shown to user which * means that the server details were potentially updated. */ public boolean handleUnknownHostException(UnknownHostException exception) { // create custom error message with the option to open the preferences // dialog MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$ null, (I18N.get("Unknown server: \"{0}\"", exception.getLocalizedMessage()) //$NON-NLS-1$ + "\n\n" //$NON-NLS-1$ + I18N.getString("Please check your Mindquarry server URL in the preferences dialog.")), //$NON-NLS-1$ MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$ I18N.getString("Cancel") //$NON-NLS-1$ }, 0); int buttonClicked = messageDialog.open(); switch (buttonClicked) { case 0: // go to preferences showPreferenceDialog(true); return true; case 1: // cancel displayNotConnected(); return false; } return false; }
From source file:com.mindquarry.desktop.client.MindClient.java
License:Open Source License
/** * Displays an error message and prompts the user to check their credentials * in the preferences dialog, or to cancel. * //from w w w . ja v a 2s. co m * @param exception * Contains the error message to be displayed. * @return True if and only if preferences dialog was shown to user which * means that the credentials were potentially updated. */ public boolean handleMalformedURLException(MalformedURLException exception) { // create custom error message with the option to open the preferences // dialog MessageDialog messageDialog = new MessageDialog(getShell(), I18N.getString("Error"), //$NON-NLS-1$ null, I18N.get( "Invalid server URL given: {0}\n\nPlease check your server settings in the preferences dialog.", exception.getLocalizedMessage()), MessageDialog.ERROR, new String[] { I18N.getString("Go to preferences"), //$NON-NLS-1$ I18N.getString("Cancel") //$NON-NLS-1$ }, 0); int buttonClicked = messageDialog.open(); switch (buttonClicked) { case 0: // go to preferences showPreferenceDialog(true); return true; case 1: // cancel displayNotConnected(); return false; } return false; }
From source file:com.mobilesorcery.sdk.importproject.MoSyncWizardProjectsImportPage.java
License:Open Source License
/** * The <code>WizardDataTransfer</code> implementation of this * <code>IOverwriteQuery</code> method asks the user whether the existing * resource at the given path should be overwritten. * * @param pathString/*from w w w . ja v a 2s . com*/ * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, * <code>"ALL"</code>, or <code>"CANCEL"</code> */ @Override public String queryOverwrite(String pathString) { Path path = new Path(pathString); String messageString; // Break the message up if there is a file name and a directory // and there are at least 2 segments. if (path.getFileExtension() == null || path.segmentCount() < 2) { messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString); } else { messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question, null, messageString, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0) { @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL }; // run in syncExec because callback is from an operation, // which is probably not running in the UI thread. getControl().getDisplay().syncExec(new Runnable() { @Override public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()]; }
From source file:com.mobilesorcery.sdk.internal.launch.EmulatorLaunchConfigurationDelegate.java
License:Open Source License
private boolean showSwitchConfigDialog(MoSyncProject mosyncProject, String mode, final IBuildConfiguration activeCfg, String[] requiredTypes) { if (isDebugMode(mode)) { Display d = PlatformUI.getWorkbench().getDisplay(); final boolean[] result = new boolean[1]; d.syncExec(new Runnable() { @Override// ww w .ja va2 s.c om public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog dialog = new MessageDialog(shell, "Incompatible build configuration", null, MessageFormat.format( "The build configuration \"{0}\" is not intended for debugging. Debug anyway?", activeCfg.getId()), MessageDialog.WARNING, new String[] { "Debug", "Cancel" }, 1); result[0] = dialog.open() == 0; } }); return result[0]; } return true; }
From source file:com.mobilesorcery.sdk.ui.MosyncUIPlugin.java
License:Open Source License
protected void checkConfig(final IWorkbench wb) { if (!MoSyncTool.getDefault().isValid()) { wb.getDisplay().syncExec(new Runnable() { public void run() { MessageDialog dialog = new MessageDialog(wb.getModalDialogShellProvider().getShell(), "Fatal error", null, MessageFormat.format( "The environment variable MOSYNCDIR has not been properly set, or some other serious error has occurred. (Reason: {0})\n\nMoSync will not work properly. Press Ok to quit, or Cancel to continue anyway.", MoSyncTool.getDefault().validate()), MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); if (dialog.open() == IDialogConstants.OK_ID) { wb.close();//w w w . j a v a 2s . co m } } }); } }
From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java
License:Apache License
private static int showInformationDialog(final String dialogTitle, final String dialogMessage, final String detailsMessage, final String[] buttonLabels, final int dialogImageType) { final int[] returnCode = new int[1]; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); Rectangle parentSize; if (shell.getParent() != null) { parentSize = shell.getParent().getBounds(); } else { parentSize = shell.getBounds(); }// ww w. j av a 2 s . c o m MessageDialog dlg; String[] internButtonLabels = buttonLabels; if (internButtonLabels == null) { internButtonLabels = new String[] { "OK" }; } if (detailsMessage == null) { dlg = new MessageDialog(shell, dialogTitle, null, dialogMessage, dialogImageType, internButtonLabels, 0); } else { dlg = new MessageDialog(shell, dialogTitle, null, dialogMessage, dialogImageType, internButtonLabels, 0) { @Override protected Control createCustomArea(Composite parent) { final Composite main = new Composite(parent, parent.getStyle()); GridLayout layout = new GridLayout(); main.setLayout(layout); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); main.setLayoutData(data); final Button detailsButton = new Button(main, SWT.PUSH); detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_OpenDetails); data = new GridData(SWT.RIGHT, SWT.CENTER, true, false); detailsButton.setLayoutData(data); detailsButton.addSelectionListener(new SelectionAdapter() { private Label detailsText; @Override public void widgetSelected(SelectionEvent e) { if ((detailsText != null) && !detailsText.isDisposed()) { detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_OpenDetails); detailsText.dispose(); } else { detailsButton.setText(UtilitiesNLS.UI_EclipseUtils_CloseDetails); detailsText = new Label(main, SWT.WRAP | SWT.BORDER); detailsText.setText(detailsMessage); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); detailsText.setLayoutData(data); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING) .grab(true, false) .hint(convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT) .applyTo(detailsText); } getShell().pack(); } }); return main; } }; } Rectangle dialogSize = shell.getBounds(); int x = ((parentSize.width - dialogSize.width) / 2) + parentSize.x; int y = ((parentSize.height - dialogSize.height) / 2) + parentSize.y; shell.setLocation(x, y); returnCode[0] = dlg.open(); } }); return returnCode[0]; }
From source file:com.motorola.studio.android.common.utilities.EclipseUtils.java
License:Apache License
/** * Show a question message using the given title and message * /*from w ww . ja va 2 s. co m*/ * @param title * of the dialog * @param message * to be displayed in the dialog. */ public static int showQuestionWithCancelDialog(final String title, final String message) { class IntWrapper { public int diagReturn = 0; } final IntWrapper intWrapper = new IntWrapper(); Display.getDefault().syncExec(new Runnable() { public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); int diagResults = dialog.open(); switch (diagResults) { case 0: intWrapper.diagReturn = SWT.YES; break; case 1: intWrapper.diagReturn = SWT.NO; break; case 2: default: intWrapper.diagReturn = SWT.CANCEL; break; } } }); return intWrapper.diagReturn; }