Example usage for org.eclipse.jface.dialogs MessageDialog MessageDialog

List of usage examples for org.eclipse.jface.dialogs MessageDialog MessageDialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog MessageDialog.

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:com.vectrace.MercurialEclipse.views.MergeView.java

License:Open Source License

/**
 * @see com.vectrace.MercurialEclipse.views.AbstractRootView#createActions()
 *//*from ww  w  .  j  a v  a2 s . c o  m*/
@Override
protected void createActions() {
    completeAction = new Action(Messages.getString("MergeView.merge.complete")) { //$NON-NLS-1$
        @Override
        public void run() {
            if (areAllResolved()) {
                attemptToCommit();
                refresh(hgRoot, conflictResolvingContext);
            }
        }
    };
    completeAction.setEnabled(false);
    completeAction.setImageDescriptor(MercurialEclipsePlugin.getImageDescriptor("actions/commit.gif"));

    abortAction = new Action(Messages.getString("MergeView.merge.abort")) { //$NON-NLS-1$
        @Override
        public void run() {
            try {
                RunnableHandler runnable;
                if (!merging) {
                    runnable = new AbortRebaseHandler();
                } else {
                    UpdateHandler update = new UpdateHandler();
                    update.setCleanEnabled(true);
                    update.setRevision(".");
                    runnable = update;
                }

                runnable.setShell(table.getShell());
                runnable.run(hgRoot);
                refresh(hgRoot, conflictResolvingContext);
            } catch (CoreException e) {
                handleError(e);
            }
            MercurialUtilities.setOfferAutoCommitMerge(true);
        }
    };
    abortAction.setEnabled(false);
    abortAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_STOP));

    markResolvedAction = new Action(Messages.getString("MergeView.markResolved")) { //$NON-NLS-1$
        @Override
        public void run() {
            try {
                List<IFile> files = getSelections();
                if (files != null) {
                    for (IFile file : files) {
                        KeepDeleteConflict c = keepDeleteConflicts.get(file);
                        if (c != null) {
                            // just remove it from the list..
                            conflictResolvingContext.getKeepDeleteConflicts().remove(c);
                        } else {
                            HgResolveClient.markResolved(hgRoot, file);
                        }
                    }
                    populateView(true);
                }
            } catch (HgException e) {
                handleError(e);
            }
        }
    };
    markResolvedAction.setEnabled(false);
    markUnresolvedAction = new Action(Messages.getString("MergeView.markUnresolved")) { //$NON-NLS-1$
        @Override
        public void run() {
            try {
                List<IFile> files = getSelections();
                if (files != null) {
                    for (IFile file : files) {
                        KeepDeleteConflict c = keepDeleteConflicts.get(file);
                        // do nothing for keep-delete conflicts
                        if (c == null) {
                            HgResolveClient.markUnresolved(hgRoot, file);
                        }

                    }
                    populateView(true);
                }
            } catch (HgException e) {
                handleError(e);
            }
        }
    };
    markUnresolvedAction.setEnabled(false);

    deleteFileAction = new Action(Messages.getString("MergeView.deleteFile")) {
        @Override
        public void run() {
            super.run();
            try {
                List<IFile> files = getSelections();
                if (files != null) {
                    for (IFile file : files) {
                        KeepDeleteConflict c = keepDeleteConflicts.get(file);
                        if (c != null) {
                            try {
                                HgResolveClient.deleteKeepDeleteConflict(hgRoot, conflictResolvingContext, c,
                                        file);
                            } catch (Exception ex) {
                                // just in case, I've seen some random failures when the workspace isn't in sync with the file system
                                MessageDialog dialog = new MessageDialog(null, "Error Deleting File", null,
                                        ex.getMessage(), MessageDialog.ERROR, new String[] { "Ok" }, 0);
                            }
                        } else {
                            // even if it's not a keep-delete conflict, we are providing a delete file option,
                            // so delete the file either way.
                            try {
                                file.delete(true, null);
                            } catch (Exception ex) {
                                MessageDialog dialog = new MessageDialog(null, "Error Deleting File", null,
                                        ex.getMessage(), MessageDialog.ERROR, new String[] { "Ok" }, 0);
                            }
                        }

                        // refresh status
                        MercurialStatusCache.getInstance().refreshStatus(file, null);
                        ResourceUtils.touch(file);
                    }
                    populateView(true);
                }
            } catch (HgException e) {
                handleError(e);
            }
        }
    };
    deleteFileAction.setEnabled(false);
}

From source file:com.vectrace.MercurialEclipse.wizards.ProjectsImportPage.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  ww w  . jav a2 s.co  m*/
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
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 = "'" + pathString + "' already exists.  Would you like to overwrite it?";
    } else {
        messageString = "Overwrite '" + path.lastSegment() + "' in folder '"
                + path.removeLastSegments(1).toOSString() + "'?";
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "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() {
            // TODO add  "| SWT.SHEET" flag as soon as we drop Eclipse 3.4 support
            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() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.vmware.vfabric.ide.eclipse.tcserver.insight.internal.ui.TcServerInsightSection.java

License:Open Source License

@Override
public void createSection(Composite parent) {
    super.createSection(parent);
    FormToolkit toolkit = getFormToolkit(parent.getDisplay());

    Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR
            | Section.DESCRIPTION | ExpandableComposite.FOCUS_TITLE | ExpandableComposite.EXPANDED);
    section.setText("Overview");
    section.setDescription("Enable collection of performance metrics for deployed applications.");
    section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    Composite composite = toolkit.createComposite(section);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 8;//from  w  w  w .  j a v  a  2  s .  co  m
    layout.marginWidth = 8;
    composite.setLayout(layout);
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    button = toolkit.createButton(composite, "Enable gathering of metrics", SWT.CHECK);
    button.addSelectionListener(new SelectionAdapter() {
        private boolean ignoreEvents;

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (ignoreEvents) {
                return;
            }
            if (button.getSelection() && server.getOriginal() != null
                    && !TcServerInsightUtil.isInsightCompatible(server.getOriginal())) {
                MessageDialog dialog = new MessageDialog(getShell(), "Enable Spring Insight", null,
                        "This version of Spring Insight is not compatible with tc Server instances that are installed on a path that contains spaces. Enabling Spring Insight may cause tc Server to fail to startup.\n\n"
                                + "Are you sure you want to enable Spring Insight?",
                        MessageDialog.ERROR,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
                if (dialog.open() != 0) {
                    try {
                        ignoreEvents = true;
                        button.setSelection(false);
                    } finally {
                        ignoreEvents = false;
                    }
                    return;
                }
            }
            execute(new ModifyInsightVmArgsCommand(serverInstance, button.getSelection()));
        }
    });
    GridDataFactory.fillDefaults().span(2, 1).applyTo(button);

    initialize();
}

From source file:com.wakatime.eclipse.plugin.WakaTime.java

@Override
public void earlyStartup() {
    final IWorkbench workbench = PlatformUI.getWorkbench();

    // listen for save file events
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    executionListener = new CustomExecutionListener();
    commandService.addExecutionListener(executionListener);

    workbench.getDisplay().asyncExec(new Runnable() {
        public void run() {
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            if (window == null)
                return;

            // prompt for apiKey if not set
            MenuHandler handler = new MenuHandler();
            DEBUG = handler.getDebug();//from   w w  w.j  av a  2  s. c o  m
            String apiKey = handler.getApiKey();
            if (apiKey == "") {
                handler.promptForApiKey(window);
            }

            Dependencies deps = new Dependencies();

            if (!deps.isPythonInstalled()) {
                deps.installPython();
                if (!deps.isPythonInstalled()) {
                    MessageDialog dialog = new MessageDialog(window.getShell(), "Warning!", null,
                            "WakaTime needs Python installed. Please install Python from python.org/downloads, then restart Eclipse.",
                            MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL }, 0);
                    dialog.open();
                }
            }
            if (!deps.isCLIInstalled()) {
                deps.installCLI();
            }

            if (window.getPartService() == null)
                return;

            // listen for caret movement
            if (window.getPartService().getActivePartReference() != null
                    && window.getPartService().getActivePartReference().getPage() != null
                    && window.getPartService().getActivePartReference().getPage().getActiveEditor() != null) {
                IEditorPart part = window.getPartService().getActivePartReference().getPage().getActiveEditor();
                if (!(part instanceof AbstractTextEditor))
                    return;
                ((StyledText) part.getAdapter(Control.class)).addCaretListener(new CustomCaretListener());
            }

            // listen for change of active file
            window.getPartService().addPartListener(editorListener);

            if (window.getPartService().getActivePart() == null)
                return;
            if (window.getPartService().getActivePart().getSite() == null)
                return;
            if (window.getPartService().getActivePart().getSite().getPage() == null)
                return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null)
                return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor()
                    .getEditorInput() == null)
                return;

            // log file if one is opened by default
            IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor()
                    .getEditorInput();
            if (input instanceof IURIEditorInput) {
                URI uri = ((IURIEditorInput) input).getURI();
                if (uri != null && uri.getPath() != null) {
                    String currentFile = uri.getPath();
                    long currentTime = System.currentTimeMillis() / 1000;
                    if (!currentFile.equals(WakaTime.getDefault().lastFile)
                            || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                        WakaTime.logFile(currentFile, WakaTime.getActiveProject(), false);
                        WakaTime.getDefault().lastFile = currentFile;
                        WakaTime.getDefault().lastTime = currentTime;
                    }
                }
            }

            WakaTime.log("Finished initializing WakaTime plugin (https://wakatime.com) v" + VERSION);
        }
    });
}

From source file:com.windowtester.eclipse.ui.target.NewTargetProvisionerPage.java

License:Open Source License

protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", (Image) null, message,
            MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    // ensure yes is the default

    return dialog.open() == 0;
}

From source file:com.windowtester.test.eclipse.locator.DialogMessageLocatorSmokeTest.java

License:Open Source License

public void testInfoTextIdentification() throws WidgetSearchException {

    final Label[] label = new Label[1];
    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            MessageDialog dialog = new MessageDialog(getShell(), "Info", null, "Something",
                    MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0) {

                public void create() {
                    super.create();
                    label[0] = this.messageLabel; //cache label
                }/* ww  w.j a  v  a  2 s  .  c  o  m*/
            };
            dialog.open();
        }
    });

    IUIContext ui = getUI();
    ui.wait(new ShellShowingCondition("Info"));

    assertIsMessageLocator(identify(label[0]));

    ui.assertThat(new DialogMessageLocator().hasText("Something"));
    ui.click(new ButtonLocator("OK"));
    ui.wait(new ShellDisposedCondition("Info"));
}

From source file:com.windowtester.test.runtime.CloseNestedShellsTest.java

License:Open Source License

public void uiSetup() {
    Shell shell = new Shell(Display.getDefault());
    dialog = new MessageDialog(shell, "First Shell", null, "message", MessageDialog.INFORMATION,
            new String[] { IDialogConstants.OK_LABEL }, 0) {

        /* (non-Javadoc)
         * @see org.eclipse.jface.dialogs.Dialog#close()
         *//* w w  w . ja  va  2 s  . c o m*/
        @Override
        public boolean close() {
            boolean confirmed = MessageDialog.openConfirm(getShell(), "Nested", "Nested Shell");
            if (confirmed)
                return super.close();
            return false;
        }

    };

    dialog.open();
}

From source file:cu.uci.abos.core.util.MessageDialogUtil.java

License:Open Source License

private static void open(int kind, Shell parent, String title, String message, final DialogCallback callback) {
    String[] buttonLabels = getButtonLabels(kind);
    MessageDialog dialog = new MessageDialog(parent, title, null, message, kind, buttonLabels, 0) {

        private static final long serialVersionUID = 1L;

        @Override/*from  w ww.  j a v  a  2  s .  c  o m*/
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }

        @Override
        public boolean close() {
            boolean result = super.close();
            if (callback != null) {
                callback.dialogClosed(getReturnCode());
            }
            return result;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java

License:Open Source License

@Override
public boolean performOk() {
    boolean save = true;
    if (!CommandDataStore.instance().isMigrated()) {
        String title = Activator.getResourceString("easyshell.command.page.dialog.migration.title");
        String question = Activator.getResourceString("easyshell.command.page.dialog.migration.question");
        MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.WARNING,
                new String[] { "Yes", "No" }, 1); // no is the default
        int result = dialog.open();
        if (result == 0) {
            CommandDataStore.instance().setMigrated(true);
        } else {//from   w ww .j a va  2 s  .  c o m
            save = false;
        }
    }
    if (save) {
        CommandDataStore.instance().save();
        MenuDataStore.instance().save();
    }
    return save;
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java

License:Open Source License

@Override
protected void performDefaults() {
    // get the selected commands and referenced menus as lists
    CommandDataList commands = new CommandDataList(CommandDataStore.instance().getDataList());
    List<MenuData> menus = new ArrayList<MenuData>();
    for (CommandData command : commands) {
        if (command.getPresetType() == PresetType.presetUser) {
            List<MenuData> menusForOne = MenuDataStore.instance().getRefencedBy(command.getId());
            menus.addAll(menusForOne);//from ww  w .ja va  2 s  .  co  m
        }
    }
    String title = Activator.getResourceString("easyshell.command.page.dialog.defaults.title");
    String question = Activator.getResourceString("easyshell.command.page.dialog.defaults.question");
    int dialogImageType = MessageDialog.QUESTION;
    if (menus.size() >= 0) {
        dialogImageType = MessageDialog.WARNING;
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.defaults.menu.question"), menuNames);
    }
    MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        if (menus.size() >= 0) {
            for (MenuData menu : menus) {
                MenuDataStore.instance().delete(menu);
            }
            //MenuDataStore.instance().save();
        }
        CommandDataStore.instance().loadDefaults();
        tableViewer.refresh();
    }
}