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

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

Introduction

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

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:org.eclipse.birt.report.designer.ui.internal.rcp.dialogs.SaveAsDialog.java

License:Open Source License

protected void okPressed() {
    // Get new path.
    IPath path = support.getFileLocationFullPath().append(support.getFileName());

    // If the user does not supply a file extension and the save
    // as dialog was provided a default file name, then append the extension
    // of the default filename to the new name
    if (!ReportPlugin.getDefault().isReportDesignFile(path.toOSString())) {
        String[] parts = support.getInitialFileName().split("\\."); //$NON-NLS-1$
        path = path.addFileExtension(parts[parts.length - 1]);
    }//from  w  w  w . j av  a 2  s  .co  m

    // If the path already exists then confirm overwrite.
    File file = path.toFile();
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };

        String question = Messages.getFormattedString("SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
                new Object[] { path.toOSString() });
        MessageDialog d = new MessageDialog(getShell(), Messages.getString("SaveAsDialog.Question"), //$NON-NLS-1$
                null, question, MessageDialog.QUESTION, buttons, 0);
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return;
        case 2: // Cancel
        default:
            cancelPressed();
            return;
        }
    }

    // Store path and close.
    result = path;
    close();
}

From source file:org.eclipse.birt.report.designer.ui.lib.explorer.dialog.PublishResourceWizard.java

License:Open Source License

private boolean publishiLibrary() {
    // copy to library folder

    if (!(new File(filePath).exists())) {
        ExceptionUtil.openError(Messages.getString("PublishResourceAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishResourceAction.wizard.message.SourceFileNotExist")); //$NON-NLS-1$

        return false;
    }/*from w w  w  .  ja  v  a  2s .com*/

    File targetFile = getTargetFile();

    if (targetFile == null) {
        ExceptionUtil.openError(Messages.getString("PublishResourceAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishResourceAction.wizard.notvalidfolder")); //$NON-NLS-1$

        return false;
    }

    if (new File(filePath).compareTo(targetFile) == 0) {
        ExceptionUtil.openError(Messages.getString("PublishResourceAction.wizard.errorTitle"), //$NON-NLS-1$
                Messages.getString("PublishResourceAction.wizard.message")); //$NON-NLS-1$
        return false;
    }

    int overwrite = Window.OK;
    try {
        if (targetFile.exists()) {
            String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL };

            String question = Messages.getFormattedString("SaveAsDialog.overwriteQuestion", //$NON-NLS-1$
                    new Object[] { targetFile.getAbsolutePath() });

            MessageDialog d = new MessageDialog(UIUtil.getDefaultShell(),
                    Messages.getString("SaveAsDialog.Question"), //$NON-NLS-1$
                    null, question, MessageDialog.QUESTION, buttons, 0);

            overwrite = d.open();
        }
        if (overwrite == Window.OK
                && (targetFile.exists() || (!targetFile.exists() && targetFile.createNewFile()))) {
            doCopy(filePath, targetFile);

            IReportResourceSynchronizer synchronizer = ReportPlugin.getDefault()
                    .getResourceSynchronizerService();

            if (synchronizer != null) {
                synchronizer.notifyResourceChanged(
                        new ReportResourceChangeEvent(this, Path.fromOSString(targetFile.getAbsolutePath()),
                                IReportResourceChangeEvent.NewResource));
            }
        }
    } catch (IOException e) {
        ExceptionUtil.handle(e);
    }

    return overwrite != 2;
}

From source file:org.eclipse.bpmn2.modeler.core.validation.BPMN2ProjectValidator.java

License:Open Source License

public static boolean validateOnSave(Resource resource, IProgressMonitor monitor) {

    boolean needValidation = false;
    URI uri = resource.getURI();//w w w  . j ava  2  s .co  m
    if (uri.isPlatformResource()) {
        String pathString = uri.toPlatformString(true);
        IPath path = Path.fromOSString(pathString);
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        IProject project = file.getProject();

        if (project != null) {
            try {
                IProjectNature nature = project.getNature(BPMN2Nature.NATURE_ID);
                if (nature == null) {
                    Bpmn2Preferences preferences = Bpmn2Preferences.getInstance(project);
                    if (preferences.getCheckProjectNature()) {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        String title = Messages.BPMN2ProjectValidator_Title;
                        String message = NLS.bind(Messages.BPMN2ProjectValidator_No_Project_Nature,
                                project.getName());
                        MessageDialogWithToggle result = MessageDialogWithToggle.open(MessageDialog.QUESTION,
                                shell, title, message, Messages.BPMN2ProjectValidator_Dont_Ask_Again, // toggle message
                                false, // toggle state
                                null, // pref store
                                null, // pref key
                                SWT.NONE);
                        if (result.getReturnCode() == IDialogConstants.YES_ID) {
                            IProjectDescription description = project.getDescription();
                            String[] natures = description.getNatureIds();
                            String[] newNatures = new String[natures.length + 1];
                            System.arraycopy(natures, 0, newNatures, 0, natures.length);
                            newNatures[natures.length] = BPMN2Nature.NATURE_ID;
                            description.setNatureIds(newNatures);
                            project.setDescription(description, null);
                            needValidation = true;
                        }
                        if (result.getToggleState()) {
                            // don't ask again
                            preferences.setCheckProjectNature(false);
                        }
                    }
                } else
                    needValidation = true;

            } catch (CoreException e) {
                e.printStackTrace();
            }
        }

        if (needValidation) {
            // validation will be done by the Project Validation builder
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.bpmn2.modeler.ui.editor.BPMN2MultiPageEditor.java

License:Open Source License

@Override
protected void createPages() {
    tabFolder = (CTabFolder) getContainer();
    tabFolder.addCTabFolder2Listener(new CTabFolder2Listener() {

        @Override/*  w  w w  .  j  ava2  s .  c o  m*/
        public void close(CTabFolderEvent event) {
            // System.out.println("Convert phase should be here");

            if (event.item.getData() == sourceViewer)
                removeSourceViewer();
            else if (event.item.getData() instanceof DiagramEditor) {
                // TODO: checking modification:
                String MESSAGE = "Resource has been modified. Save changes?";
                int choice = -1;
                DiagramEditor editor = (DiagramEditor) event.item.getData();
                if (editor.isDirty()) {
                    // ASK FOR SAVE:
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                    MessageDialog d = new MessageDialog(shell, WorkbenchMessages.Save_Resource, null, MESSAGE,
                            MessageDialog.QUESTION, buttons, 0) {
                        protected int getShellStyle() {
                            return super.getShellStyle() | SWT.SHEET;
                        }
                    };
                    choice = d.open();
                    switch (choice) {
                    case ISaveablePart2.YES: // yes                     
                        editor.doSave(new NullProgressMonitor());
                        break;
                    case ISaveablePart2.NO: // no
                        System.out.println("no");
                        break;
                    default:
                    case ISaveablePart2.CANCEL: // cancel
                        System.out.println("cancel");
                        event.doit = false;
                        return;
                    }
                }
                removeEventViewer(editor);
            }
        }

        @Override
        public void minimize(CTabFolderEvent event) {
        }

        @Override
        public void maximize(CTabFolderEvent event) {
        }

        @Override
        public void restore(CTabFolderEvent event) {
        }

        @Override
        public void showList(CTabFolderEvent event) {
        }

    });
    tabFolder.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int pageIndex = tabFolder.getSelectionIndex();
            if (pageIndex >= 0 && pageIndex < bpmnDiagrams.size() && designEditor != null) {
                BPMNDiagram bpmnDiagram = bpmnDiagrams.get(pageIndex);
                designEditor.selectBpmnDiagram(bpmnDiagram);
            }
        }
    });

    // defer editor layout until all pages have been created
    tabFolder.setLayoutDeferred(true);

    createDesignEditor();

    Display.getDefault().asyncExec(new Runnable() {
        public void run() {
            setActivePage(0);
            designEditor.selectBpmnDiagram(bpmnDiagrams.get(0));
            tabFolder.setLayoutDeferred(false);
            tabFolder.setTabPosition(SWT.TOP);
            updateTabs();
        }
    });
}

From source file:org.eclipse.bpmn2.modeler.ui.editor.BPMN2MultiPageEditor.java

License:Open Source License

public void createEventViewer(ReceiveTask task, String nid, String text, EEventBaseScript ebs) {
    boolean recreateDiagram = false;
    EventViewer eventView = null;//w  ww  .  j a  v a2  s .  co  m
    for (EditorPart ed : mapping.keySet()) {
        if (ed instanceof EventViewer) {
            if (((EventViewer) ed).id.equals(nid)) {
                setActivePage(((EventViewer) ed).index);
                return;
            }
        }
    }
    try {
        int pageIndex = tabFolder.getItemCount();
        IContainer folder = designEditor.getModelFile().getParent();

        IFile target = null;
        try {
            if (folder instanceof Container) {
                target = ((Container) folder).getFile(nid + ".evb");
                target = ResourcesPlugin.getWorkspace().getRoot()
                        .getFile(folder.getFullPath().addTrailingSeparator().append(nid + ".evb"));
            } else
                log.error("cannot get file '" + nid + ".evb' from folder " + folder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (target.exists()) {
            log.debug("target exists -> check matching and openfile?");
            String lastFileHash = task.getFileHash();
            String lastScriptHash = task.getScriptHash();
            if (task.getEventScript() == null || lastFileHash == null || lastScriptHash == null) {
                recreateDiagram = true;
            } else {
                String fileHash = HashUtil.getHash(target.getContents());
                String scriptHash = HashUtil.getHash(task.getEventScript());
                if (!fileHash.equals(lastFileHash) || !scriptHash.equals(lastScriptHash)) {
                    // TODO inform user that target file will be overrided!!!
                    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                    String[] buttons = new String[] { IDialogConstants.YES_LABEL,
                            //IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                    @SuppressWarnings("restriction")
                    MessageDialog d = new MessageDialog(shell, "Override exist file?", null,
                            ".evb file and the script are inconsistent. Do you want to override .evb file?",
                            MessageDialog.QUESTION, buttons, 0) {
                        protected int getShellStyle() {
                            return super.getShellStyle() | SWT.SHEET;
                        }
                    };
                    int choice = d.open();
                    switch (choice) {
                    case ISaveablePart2.YES: // yes                     
                        //editor.doSave(new NullProgressMonitor());
                        break;
                    case ISaveablePart2.NO: // no
                        System.out.println("no");
                        return;
                    default:
                    case ISaveablePart2.CANCEL: // cancel
                        System.out.println("cancel");
                        //event.doit = false;
                        return;
                    }
                    recreateDiagram = true;
                }
            }
        } else
            recreateDiagram = true;

        if (recreateDiagram) {
            recreateDiagram = true;
            log.debug("create file " + nid + ".evb and try to open it");
            // create & convert!
            final Diagram diagram = Graphiti.getPeCreateService().createDiagram(ProviderID, nid + ".evb", true);
            URI uri = URI.createPlatformResourceURI(target.getFullPath().toString(), true);
            // FileService
            @SuppressWarnings("restriction")
            final TransactionalEditingDomain editingDomain = GraphitiUiInternal.getEmfService()
                    .createResourceSetAndEditingDomain();
            final ResourceSet resourceSet = editingDomain.getResourceSet();
            final Resource resource = resourceSet.createResource(uri);
            final CommandStack cmdStack = editingDomain.getCommandStack();
            cmdStack.execute(new RecordingCommand(editingDomain) {

                @Override
                protected void doExecute() {
                    resource.setTrackingModification(true);
                    resource.getContents().add(diagram);

                }
            });
            save(editingDomain, Collections.<Resource, Map<?, ?>>emptyMap());
            editingDomain.dispose();
        }
        // FileEditorInput input = new FileEditorInput();
        String id = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(ProviderID);
        DiagramEditorInput input = new DiagramEditorInput(
                // This is, folks, it works :D
                //URI.createFileURI(target.getLocation().toOSString()),
                //URI.createFileURI(target.getFullPath().toOSString()),
                URI.createPlatformResourceURI(target.getFullPath().toString(), true), id);

        eventView = new EventViewer(task, nid, pageIndex, recreateDiagram, ebs);//TODO
        addPage(pageIndex, eventView, input);
        tabFolder.getItem(pageIndex).setShowClose(true);

        setPageText(pageIndex, nid);
        setActivePage(pageIndex);

        updateTabs();
    } catch (Exception e) {
        e.printStackTrace();
        if (eventView != null)
            eventView.dispose();
    }
}

From source file:org.eclipse.cdt.arduino.ui.internal.downloads.ArduinoDownloadsManager.java

License:Open Source License

static boolean checkLicense(Shell shell) {
    File acceptedFile = ArduinoPreferences.getArduinoHome().resolve(".accepted").toFile(); //$NON-NLS-1$
    if (!acceptedFile.exists()) {
        String message = "Do you accept the licenses for the platforms and libraries you are downloading?";
        MessageDialog dialog = new MessageDialog(shell, "Arduino Licensing", null, message,
                MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0);
        int rc = dialog.open();
        if (rc == 0) {
            try {
                acceptedFile.createNewFile();
            } catch (IOException e) {
                Activator.log(e);
            }/*ww  w.java 2  s.  c o m*/
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}

From source file:org.eclipse.cdt.arduino.ui.internal.preferences.ArduinoPlatformsPreferencePage.java

License:Open Source License

@Override
public boolean performOk() {
    File acceptedFile = ArduinoPreferences.getArduinoHome().resolve(".accepted").toFile(); //$NON-NLS-1$
    if (!acceptedFile.exists()) {
        String message = Messages.ArduinoPlatformsPreferencePage_9 + Messages.ArduinoPlatformsPreferencePage_10;
        MessageDialog dialog = new MessageDialog(getShell(), Messages.ArduinoPlatformsPreferencePage_11, null,
                message, MessageDialog.QUESTION, new String[] { Messages.ArduinoPlatformsPreferencePage_12,
                        Messages.ArduinoPlatformsPreferencePage_13 },
                0);//from   w w  w  .  j a  v  a 2 s.  c o m
        int rc = dialog.open();
        if (rc == 0) {
            try {
                acceptedFile.createNewFile();
            } catch (IOException e) {
                Activator.log(e);
            }
        } else {
            return false;
        }
    }

    new Job(Messages.ArduinoPlatformsPreferencePage_14) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 0,
                    Messages.ArduinoPlatformsPreferencePage_15, null);

            for (ArduinoPlatform platform : toUninstall) {
                status.add(platform.uninstall(monitor));
            }
            toUninstall.clear();

            for (ArduinoPlatform platform : toInstall) {
                status.add(platform.install(monitor));
            }
            toInstall.clear();

            if (table != null && !table.isDisposed()) {
                table.getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        populateTable();
                    }
                });
            }

            return status;
        }
    }.schedule();
    return true;
}

From source file:org.eclipse.cdt.cpp.ui.internal.actions.DeleteProjectAction.java

License:Open Source License

public void run() {
    ModelInterface api = ModelInterface.getInstance();
    IProject project = api.findProjectResource(_subject);
    if (project != null) {
        Shell shell = api.getDummyShell();
        String msg = "About to delete project \'" + project.getName() + "\'.\n";
        msg += "Delete all its contents under " + project.getLocation().toOSString() + " as well?";
        String title = "Delete Project Contents";

        MessageDialog dialog = new MessageDialog(shell, title, null, // accept the default window icon
                msg, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                        IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0); // yes is the default
        int code = dialog.open();
        boolean deleteContent = false;
        switch (code) {
        case 0: // Yes
            deleteContent = true;/*from   www. j  a  v a 2s.  c o m*/
            break;
        case 1: // No
            deleteContent = false;
            break;
        default: // CANCEL
            return;
        }

        DeleteOperation op = new DeleteOperation(project, api, deleteContent);
        ProgressMonitorDialog progressDlg = new ProgressMonitorDialog(shell);
        try {
            progressDlg.run(true, true, op);
        } catch (InterruptedException e) {
            System.out.println(e);
        } catch (InvocationTargetException e) {
            System.out.println(e);
        }
    }
}

From source file:org.eclipse.cdt.internal.ui.dialogs.cpaths.CPathPropertyPage.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    if (fCPathsBlock != null) {
        if (!visible) {
            if (fCPathsBlock.hasChangesInDialog()) {
                String title = CPathEntryMessages.CPathsPropertyPage_unsavedchanges_title;
                String message = CPathEntryMessages.CPathsPropertyPage_unsavedchanges_message;
                String[] buttonLabels = new String[] {
                        CPathEntryMessages.CPathsPropertyPage_unsavedchanges_button_save,
                        CPathEntryMessages.CPathsPropertyPage_unsavedchanges_button_discard, };
                MessageDialog dialog = new MessageDialog(getShell(), title, null, message,
                        MessageDialog.QUESTION, buttonLabels, 0);
                int res = dialog.open();
                if (res == 0) {
                    performOk();//www  .  j a  v a2  s  . c o m
                } else if (res == 1) {
                    fCPathsBlock.init(CoreModel.getDefault().create(getProject()), null);
                }
            }
        } else {
            if (!fCPathsBlock.hasChangesInDialog() && fCPathsBlock.hasChangesInCPathFile()) {
                fCPathsBlock.init(CoreModel.getDefault().create(getProject()), null);
            }
        }
    }
    super.setVisible(visible);
}

From source file:org.eclipse.cdt.internal.ui.dialogs.cpaths.IncludesSymbolsPropertyPage.java

License:Open Source License

@Override
public void setVisible(boolean visible) {
    if (fIncludesSymbolsBlock != null) {
        if (!visible) {
            if (fIncludesSymbolsBlock.hasChangesInDialog()) {
                String title = CPathEntryMessages.CPathsPropertyPage_unsavedchanges_title;
                String message = CPathEntryMessages.CPathsPropertyPage_unsavedchanges_message;
                String[] buttonLabels = new String[] {
                        CPathEntryMessages.CPathsPropertyPage_unsavedchanges_button_save,
                        CPathEntryMessages.CPathsPropertyPage_unsavedchanges_button_discard, };
                MessageDialog dialog = new MessageDialog(getShell(), title, null, message,
                        MessageDialog.QUESTION, buttonLabels, 0);
                int res = dialog.open();
                if (res == 0) {
                    performOk();// w w w  . j a  v  a 2  s.  co  m
                } else if (res == 1) {
                    fIncludesSymbolsBlock.init(getCElement(), null);
                }
            }
        } else {
            if (!fIncludesSymbolsBlock.hasChangesInDialog() && fIncludesSymbolsBlock.hasChangesInCPathFile()) {
                fIncludesSymbolsBlock.init(getCElement(), null);
            }
        }
    }
    super.setVisible(visible);
}