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

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

Introduction

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

Prototype

public static boolean openQuestion(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple Yes/No question dialog.

Usage

From source file:com.ebmwebsourcing.petals.server.actions.ShutdownPetalsServerAction.java

License:Open Source License

public void run(IAction action) {

    if (this.server != null) {

        boolean shutdown = MessageDialog.openQuestion(this.shell, "Shutdown the server?",
                "Are you sure you want to shutdown Petals?\n"
                        + "Every deployed artefact will be deleted by this action.");

        if (shutdown) {
            action.setEnabled(true);//from ww  w. j  av  a2  s  .  c  o  m
            PetalsServerBehavior behavior = (PetalsServerBehavior) this.server
                    .loadAdapter(PetalsServerBehavior.class, null);

            if (behavior != null)
                behavior.stop(true, false);
        }
    }
}

From source file:com.ebmwebsourcing.petals.services.jsr181.handlers.Jsr181GenerationHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

    final IJavaProject javaProject = getSelectedJavaProject();
    if (javaProject != null) {

        // Need for a confirmation?
        String msg = "Would you like to generate a new jbi.xml file right after the WSDL generation?\n"
                + "This jbi.xml will rely on all the generated WSDL definitions.\n\n"
                + "Please, note this will overwrite the existing one.";

        final boolean generateJbiXml = MessageDialog.openQuestion(new Shell(), "Also generate a new jbi.xml?",
                msg);//from   w  ww  .  j  a v a  2 s . c om

        // Define the generation context
        WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {

                try {
                    monitor.beginTask("Generating Petals required files...", IProgressMonitor.UNKNOWN);
                    generateJsr181Files(javaProject, generateJbiXml, monitor);

                } finally {
                    monitor.done();
                }
            }
        };

        // Run it
        try {
            IProgressService ps = PlatformUI.getWorkbench().getProgressService();
            ps.busyCursorWhile(op);

        } catch (InterruptedException e) {
            // nothing

        } catch (InvocationTargetException e) {
            PetalsJsr181Plugin.log(e, IStatus.ERROR,
                    "A problem occurred while generating files for the JSR-181.");
            MessageDialog.openError(new Shell(), "Generation Error",
                    "A problem occurred while generating files for the JSR-181.\nCheck the log for more details.");
        }
    }

    return null;
}

From source file:com.ebmwebsourcing.petals.services.preferences.MavenPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);/*from  w  w w. java 2  s. com*/
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Petals Maven plug-in
    Group group = new Group(container, SWT.NONE);
    group.setLayout(new GridLayout(3, false));
    GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 3;
    layoutData.verticalIndent = 4;
    group.setLayoutData(layoutData);
    group.setText("Petals Maven plug-in");

    Composite subContainer = new Composite(group, SWT.NONE);
    subContainer.setLayout(new GridLayout());
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    this.pluginVersionField = new StringFieldEditor(PreferencesManager.PREFS_MAVEN_PLUGIN_VERSION,
            "Plugin Version:", StringFieldEditor.UNLIMITED, subContainer);
    this.pluginVersionField.fillIntoGrid(subContainer, 3);
    this.pluginVersionField.setPage(this);
    this.pluginVersionField.setPreferenceStore(getPreferenceStore());
    this.pluginVersionField.load();

    this.groupIdField = new StringFieldEditor(PreferencesManager.PREFS_MAVEN_GROUP_ID, "Group ID:",
            StringFieldEditor.UNLIMITED, subContainer);
    this.groupIdField.fillIntoGrid(subContainer, 3);
    this.groupIdField.setPage(this);
    this.groupIdField.setPreferenceStore(getPreferenceStore());
    this.groupIdField.load();

    this.pomParentField = new FileUrlFieldEditor(PreferencesManager.PREFS_MAVEN_POM_PARENT, "POM Parent:", true,
            StringFieldEditor.VALIDATE_ON_KEY_STROKE, subContainer);
    this.pomParentField.setFileExtensions(new String[] { "*.xml" });
    this.pomParentField.setPage(this);
    this.pomParentField.setPreferenceStore(getPreferenceStore());
    this.pomParentField.load();

    // Work with customized POM
    group = new Group(container, SWT.NONE);
    group.setLayout(new GridLayout(4, false));
    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 3;
    layoutData.verticalIndent = 10;
    group.setLayoutData(layoutData);
    group.setText("POM customization");

    subContainer = new Composite(group, SWT.NONE);
    subContainer.setLayout(new GridLayout());
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    this.defaultButton = new Button(subContainer, SWT.RADIO);
    this.defaultButton.setText("Use default POM");
    layoutData = new GridData();
    layoutData.horizontalSpan = 3;
    this.defaultButton.setLayoutData(layoutData);

    this.customizedButton = new Button(subContainer, SWT.RADIO);
    this.customizedButton.setText("Use customized POM");
    layoutData = new GridData();
    layoutData.horizontalSpan = 3;
    this.customizedButton.setLayoutData(layoutData);

    // The next field must only validate the location if it is enabled
    this.customizedPomLocationField = new DirectoryFieldEditor(PreferencesManager.PREFS_CUSTOMIZED_POM_LOCATION,
            "POM templates:", subContainer) {

        @Override
        protected boolean checkState() {

            boolean result = true;
            if (MavenPreferencePage.this.useCustomizedPom)
                result = super.checkState();
            else
                clearErrorMessage();

            return result;
        }

        @Override
        public void setEnabled(boolean enabled, Composite parent) {
            super.setEnabled(enabled, parent);
            valueChanged();
        }
    };

    this.customizedPomLocationField.setErrorMessage("The POM templates location is not a valid directory.");
    this.customizedPomLocationField.setPage(this);
    this.customizedPomLocationField.setPreferenceStore(getPreferenceStore());
    this.customizedPomLocationField.load();

    // Add a hyper link to generate the default POM
    final Link hyperlink = new Link(subContainer, SWT.NONE);
    hyperlink.setText("<A>Generate the default POM templates</A>");
    layoutData = new GridData(SWT.TRAIL, SWT.DEFAULT, true, false);
    layoutData.horizontalSpan = 2;
    hyperlink.setLayoutData(layoutData);

    // Add the listeners
    this.customizedPomLocationField.setPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (FieldEditor.VALUE.equals(event.getProperty())) {

                boolean valid = MavenPreferencePage.this.customizedPomLocationField.isValid();
                hyperlink.setEnabled(valid);
                setValid(valid);
            }
        }
    });

    SelectionListener selectionListener = new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            MavenPreferencePage.this.useCustomizedPom = MavenPreferencePage.this.customizedButton
                    .getSelection();
            MavenPreferencePage.this.customizedPomLocationField.setEnabled(
                    MavenPreferencePage.this.useCustomizedPom,
                    MavenPreferencePage.this.customizedButton.getParent());

            if (MavenPreferencePage.this.useCustomizedPom)
                hyperlink.setEnabled(MavenPreferencePage.this.customizedPomLocationField.isValid());
            else
                hyperlink.setEnabled(false);
        }
    };

    this.defaultButton.addSelectionListener(selectionListener);
    this.customizedButton.addSelectionListener(selectionListener);
    this.defaultButton.setSelection(!this.useCustomizedPom);
    this.customizedButton.setSelection(this.useCustomizedPom);
    this.customizedButton.notifyListeners(SWT.Selection, new Event());

    hyperlink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {

            // Get the situation
            File rootDirectory = new File(MavenPreferencePage.this.customizedPomLocationField.getStringValue());
            File suPom = new File(rootDirectory, PetalsServicePomManager.DEFAULT_SU_POM);
            File saPom = new File(rootDirectory, PetalsServicePomManager.DEFAULT_SA_POM);

            boolean overwrite = false;
            if (suPom.exists() || saPom.exists()) {
                String msg = "Some of the default POM templates already exist.\nDo you want to overwrite them?";
                overwrite = MessageDialog.openQuestion(hyperlink.getShell(), "Overwrite Templates", msg);
            }

            // Create the SU template
            boolean ok = true;
            if (!suPom.exists() || overwrite) {
                File tpl = getBundledTemplateFile(true);
                try {
                    IoUtils.copyStream(tpl, suPom);

                } catch (IOException e1) {
                    ok = false;
                    PetalsServicesPlugin.log(e1, IStatus.ERROR);
                }
            }

            // Create the SA template
            if (!saPom.exists() || overwrite) {
                File tpl = getBundledTemplateFile(false);
                try {
                    IoUtils.copyStream(tpl, saPom);

                } catch (IOException e1) {
                    ok = false;
                    PetalsServicesPlugin.log(e1, IStatus.ERROR);
                }
            }

            // Report the result
            if (ok) {
                MessageDialog.openInformation(hyperlink.getShell(), "Successful Creation",
                        "The default POM templates were successfully created.");
            } else {
                MessageDialog.openError(hyperlink.getShell(), "Error during the Creation",
                        "The default POM templates could not be created correctly.\nCheck the log for more details.");
            }
        }
    });

    // Update POM dependencies automatically
    group = new Group(container, SWT.NONE);
    group.setLayout(new GridLayout());
    layoutData = new GridData(GridData.FILL_HORIZONTAL);
    layoutData.horizontalSpan = 3;
    layoutData.verticalIndent = 10;
    group.setLayoutData(layoutData);
    group.setText("POM dependencies");

    subContainer = new Composite(group, SWT.NONE);
    subContainer.setLayout(new GridLayout());

    this.autoPomUpdateField = new BooleanFieldEditor(PreferencesManager.PREFS_UPDATE_MAVEN_POM,
            "Update POM dependencies automatically (SA projects)", subContainer);
    this.autoPomUpdateField.setPage(this);
    this.autoPomUpdateField.setPreferenceStore(getPreferenceStore());
    this.autoPomUpdateField.load();

    return container;
}

From source file:com.essiembre.eclipse.rbe.ui.editor.resources.FragmentResourceFactory.java

License:Open Source License

private boolean shouldNLCreatorBeUsed(IProject fragment) {
    // TODO this decision could be stored within the base file persistent 
    // properties 
    // TODO externalize/translate this message
    return MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "Translations",
            "Within the fragment project '" + fragment.getName()
                    + "' there is a 'nl'-folder containing matching resource "
                    + "bundles as well as nationalized resource bundles within the "
                    + "same folder as the base file. "
                    + "Press 'yes' to open the files from the 'nl'-folder and " + "'no' to open the others.");
}

From source file:com.flagleader.builder.BuilderManager.java

public boolean showQuestion(String paramString) {
    return MessageDialog.openQuestion(getShell(), ResourceTools.getMessage("question.dialog"), paramString);
}

From source file:com.flagleader.builder.BuilderManager.java

public void showQuestion(String paramString, IAfterAction paramIAfterAction) {
    if (MessageDialog.openQuestion(getShell(), ResourceTools.getMessage("question.dialog"), paramString))
        paramIAfterAction.ok();/*  w w  w . jav a 2s . c  o m*/
    else
        paramIAfterAction.cancel();
}

From source file:com.flamefire.importsmalinames.handlers.RenameVariablesHandler.java

License:Open Source License

private void doRename(Shell shell, ICompilationUnit cu) {
    IJavaProject proj = getProject(cu);//from  w ww.  j  av  a 2 s . c  om
    String cClassName = null;
    String pName = null;
    try {
        cClassName = cu.getCorrespondingResource().getName();
        if (proj != null)
            pName = proj.getElementName();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    if (cClassName == null || pName == null || cClassName.length() == 0 || pName.length() == 0) {
        MessageDialog.openError(shell, "Error", "Could not access project and class names");
        return;
    }
    boolean classOnly = MessageDialog.openQuestion(shell, "Apply smali names only to current class?",
            "Do you want to apply the names only to current java file (" + cClassName + ") ->YES\n"
                    + "Or to the whole project (" + pName + ") -> NO");
    String lastFolder = null;
    IResource res = null;
    try {
        res = proj.getCorrespondingResource();
        lastFolder = com.flamefire.importsmalinames.utils.Util.getPersistentProperty(res, LASTFOLDER);
    } catch (JavaModelException e) {
    }
    JFileChooser j = new JFileChooser();
    j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    j.setDialogTitle("Select smali directory");
    if (lastFolder != null)
        j.setSelectedFile(new File(lastFolder));
    if (j.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
        return;
    com.flamefire.importsmalinames.utils.Util.setPersistentProperty(res, LASTFOLDER,
            j.getSelectedFile().getAbsolutePath());
    File smaliFolder = j.getSelectedFile();
    RefactoringController controller = new RefactoringController();
    if (!controller.init(smaliFolder)) {
        MessageDialog.openError(shell, "Error", "Could not parse smali classes");
        return;
    }
    if (classOnly) {
        if (!controller.renameVariablesInFile(cu)) {
            MessageDialog.openError(shell, "Error", "Initializing the changes failed. Please check output.");
            return;
        }
    } else {
        try {
            IPackageFragment[] packages = proj.getPackageFragments();
            for (IPackageFragment mypackage : packages) {
                if (mypackage.getKind() != IPackageFragmentRoot.K_SOURCE)
                    continue;
                for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
                    if (!controller.renameVariablesInFile(unit)) {
                        if (!MessageDialog.openConfirm(shell,
                                "Error in " + unit.getCorrespondingResource().getName(),
                                "Initializing the changes to " + unit.getCorrespondingResource().getName()
                                        + " failed. Please check output.\n\nContinue?"))
                            return;
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
    String msg = "This will apply the smali names to the ";
    if (classOnly)
        msg += "java file " + cClassName;
    else
        msg += "whole project " + pName;
    msg += "\n\nPlease note that you HAVE to check the changes without a preview and it is better to apply this to the decompiled source before you do any changes yourself.";
    msg += "\nThis might fail under certain circumstances e.g. with nested classes and certain name combinations.";
    msg += "\n\nProceed?";
    if (!MessageDialog.openConfirm(shell, "Apply smali names", msg))
        return;
    if (controller.applyRenamings(shell))
        MessageDialog.openInformation(shell, "Success",
                "Names were changed. Please have a look at the output in the console for warnings and errors");
    else
        MessageDialog.openInformation(shell, "Error",
                "There were erros changing the names. Some may have been changed. Please have a look at the output in the console for warnings and errors");
}

From source file:com.generalrobotix.ui.GrxBaseItem.java

License:Open Source License

/**
 * @brief constructor/*  w  ww .j  a  v a2 s . co m*/
 * @param name name
 * @param manager manager
 */
protected GrxBaseItem(String name, GrxPluginManager manager) {
    super(name, manager);
    // delete
    Action item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxBaseItem.menu.delete"); //$NON-NLS-1$
        }

        public void run() {
            String mes = MessageBundle.get("GrxBaseItem.dialog.message.delete"); //$NON-NLS-1$
            mes = NLS.bind(mes, new String[] { GrxBaseItem.this.getName() });

            if (MessageDialog.openQuestion(null, MessageBundle.get("GrxBaseItem.dialog.title.delete"), //$NON-NLS-1$
                    mes))
                delete();
        }
    };
    setMenuItem(item);
}

From source file:com.generalrobotix.ui.item.GrxExtraJointItem.java

License:Open Source License

private void initMenu() {
    getMenu().clear();/*from  w  w  w  .j  a va2  s.c o m*/

    Action item;

    // rename
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.rename"); //$NON-NLS-1$
        }

        public void run() {
            InputDialog dialog = new InputDialog(null, getText(),
                    MessageBundle.get("GrxLinkItem.dialog.message.rename"), getName(), null); //$NON-NLS-1$
            if (dialog.open() == InputDialog.OK && dialog.getValue() != null)
                rename(dialog.getValue());
        }
    };
    setMenuItem(item);

    // delete
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxBaseItem.menu.delete"); //$NON-NLS-1$
        }

        public void run() {
            String mes = MessageBundle.get("GrxBaseItem.dialog.message.delete"); //$NON-NLS-1$
            mes = NLS.bind(mes, new String[] { getName() });
            if (MessageDialog.openQuestion(null, MessageBundle.get("GrxBaseItem.dialog.title.delete"), //$NON-NLS-1$
                    mes))
                delete();
        }
    };
    setMenuItem(item);
}

From source file:com.generalrobotix.ui.item.GrxLinkItem.java

License:Open Source License

/**
 * @brief initialize menu/*ww w.j  a v a2s .  c  o  m*/
 */
private void _initMenu() {
    getMenu().clear();

    Action item;

    // rename
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.rename"); //$NON-NLS-1$
        }

        public void run() {
            InputDialog dialog = new InputDialog(null, getText(),
                    MessageBundle.get("GrxLinkItem.dialog.message.rename"), getName(), null); //$NON-NLS-1$
            if (dialog.open() == InputDialog.OK && dialog.getValue() != null)
                rename(dialog.getValue());
        }
    };
    setMenuItem(item);

    // delete
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.delete"); //$NON-NLS-1$
        }

        public void run() {
            String mes = MessageBundle.get("GrxLinkItem.dialog.message.delete"); //$NON-NLS-1$
            mes = NLS.bind(mes, new String[] { getName() });
            if (parent_ == null) { // can't delete root link 
                MessageDialog.openInformation(null, MessageBundle.get("GrxLinkItem.dialog.title.delete0"),
                        MessageBundle.get("GrxLinkItem.dialog.message.rootLinkDelete"));
                return;
            }
            if (MessageDialog.openQuestion(null, MessageBundle.get("GrxLinkItem.dialog.title.delete0"), //$NON-NLS-1$
                    mes))
                delete();
        }
    };
    setMenuItem(item);

    // menu item : add joint
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.addJoint"); //$NON-NLS-1$
        }

        public void run() {
            InputDialog dialog = new InputDialog(null, getText(),
                    MessageBundle.get("GrxLinkItem.dialog.message.jointName"), null, null); //$NON-NLS-1$
            if (dialog.open() == InputDialog.OK && dialog.getValue() != null)
                addLink(dialog.getValue());
        }
    };
    setMenuItem(item);

    // menu item : add sensor
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.addSensor"); //$NON-NLS-1$
        }

        public void run() {
            InputDialog dialog = new InputDialog(null, getText(),
                    MessageBundle.get("GrxLinkItem.dialog.message.sensorName"), null, null); //$NON-NLS-1$
            if (dialog.open() == InputDialog.OK && dialog.getValue() != null)
                addSensor(dialog.getValue());
        }
    };
    setMenuItem(item);

    // menu item : add segment
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.addSegment"); //$NON-NLS-1$
        }

        public void run() {
            InputDialog dialog = new InputDialog(null, getText(),
                    MessageBundle.get("GrxLinkItem.dialog.message.segmentName"), null, null); //$NON-NLS-1$
            if (dialog.open() == InputDialog.OK && dialog.getValue() != null)
                addSegment(dialog.getValue());
        }
    };
    setMenuItem(item);

    // menu item : add robot
    item = new Action() {
        public String getText() {
            return MessageBundle.get("GrxLinkItem.menu.addRobot"); //$NON-NLS-1$
        }

        public void run() {
            FileDialog fdlg = new FileDialog(GrxUIPerspectiveFactory.getCurrentShell(), SWT.OPEN);
            String[] fe = { "*.wrl" };
            fdlg.setFilterExtensions(fe);
            String fPath = fdlg.open();
            if (fPath != null) {
                File f = new File(fPath);
                addRobot(f);
            }
        }
    };
    setMenuItem(item);

    /* diable copy and paste menus until they are implemented
    // menu item : copy
    item = new Action(){
    public String getText(){
        return "copy";
    }
    public void run(){
        GrxDebugUtil.println("GrxModelItem.GrxLinkItem copy Action");
        manager_.setSelectedGrxBaseItemList();
    }
    };
    setMenuItem(item);
            
    // menu item : paste
    item = new Action(){
    public String getText(){
        return "paste";
    }
    public void run(){
    }
    };
    setMenuItem(item);
    */

}