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

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

Introduction

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

Prototype

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

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:com.nokia.s60tools.compatibilityanalyser.ui.views.MainView.java

License:Open Source License

/**
 * Opens the analysis wizard.//  w ww  . jav a  2  s  . com
 *
 */
public void showWizard() {
    //First Check if web server core tools are selected in preferences
    //If yes, check whether core tools are updated or not.
    IPreferenceStore prefStore = CompatibilityAnalyserPlugin.getCompatabilityAnalyserPrefStore();
    String urlInPref = prefStore.getString(CompatibilityAnalyserPreferencesConstants.CORETOOLS_URL);
    boolean webToolsSelected = prefStore.getBoolean(CompatibilityAnalyserPreferencesConstants.WEB_TOOLS);
    if (webToolsSelected && CompatibilityAnalyserEngine.isDownloadAndExtractionNeeded(urlInPref)) {
        //If not, ask for the confirmation
        boolean okPressed = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(),
                "Compatibility Analyser",
                "Core components from Web server are in use.\nPress Ok to download them, or Cancel and change the settings in preferences page.");
        if (okPressed) {
            String status = CompatibilityAnalyserUtils.initiateDownloadingCoreTools();
            if (status != null) {
                status = status + "\n\nNote: Using the different core tools may solve your problem.";
                MessageDialog.openError(tableviewer.getControl().getShell(), "Compatibility Analyser", status);
                return;
            }
        } else {
            return;
        }
    }

    //If the opened from the view, set false 
    Runnable showWizardRunnable = new Runnable() {
        public void run() {
            WizardDialog wizDialog;
            CompatibilityAnalyserEngine engine = new CompatibilityAnalyserEngine();
            AnalysisWizard wiz = new AnalysisWizard(engine);
            wiz.setNeedsProgressMonitor(true);
            wiz.setNeedsProgressMonitor(true);
            wizDialog = new WizardDialog(getViewSite().getShell(), wiz);
            wizDialog.create();
            wizDialog.addPageChangedListener(wiz);
            wizDialog.getShell().setSize(wizDialog.getShell().getSize().x,
                    wizDialog.getShell().getSize().y + 70);
            wizDialog.open();
        }
    };

    Display.getDefault().asyncExec(showWizardRunnable);
}

From source file:com.nokia.s60tools.creator.dialogs.AbstractDialog.java

License:Open Source License

/**
 * Show an confirmation dialog//from  w w w  . jav  a  2  s.  c o  m
 * @param title
 * @param message
 * @return true if OK pressed, false otherwise
 */
protected boolean showConfirmationDialog(String title, String message) {
    Shell sh;
    if (getShell() != null) {
        try {
            sh = getShell();
        } catch (SWTException e) {
            sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
        }

    } else {
        sh = CreatorActivator.getCurrentlyActiveWbWindowShell();
    }

    return MessageDialog.openConfirm(sh, title, message);
}

From source file:com.nokia.sdt.sourcegen.SourceGenPlugin.java

License:Open Source License

/**
 * Check that the workspace is synchronized and in a 
 * sane state to save sources./*  ww w.j a v  a2  s.  c o  m*/
 * @return true: everything is up-to-date, false: cancel the save
 */
private boolean checkSynchronizedWorkspace(IDesignerDataModel dataModel) {
    // ask to save any source editors
    if (dataModel.getProjectContext() == null)
        return true;
    final IProject theProject = dataModel.getProjectContext().getProject();
    if (theProject == null)
        return true;

    IEditorPartFilter filter = new IEditorPartFilter() {

        public boolean accept(IEditorPart part) {
            // only look at stuff in this project
            IResource rsrc = (IResource) part.getEditorInput().getAdapter(IResource.class);
            if (rsrc != null) {
                IProject project = rsrc.getProject();
                if (project == null || !project.equals(theProject))
                    return false;
            }
            String name = part.getEditorInput().getName();
            return sourcePattern.matcher(name).matches();
        }
    };
    if (!saveAllSourceEditors(filter, true))
        return false;

    // check for changes made outside workspace
    IProject project = null;
    if (dataModel.getProjectContext() != null
            && (project = dataModel.getProjectContext().getProject()) != null) {

        final List<IPath> unsynchronizedResources = new ArrayList<IPath>();

        IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
            public boolean visit(IResourceProxy resourceProxy) throws CoreException {
                String name = resourceProxy.getName();
                boolean looksLikeSource = sourcePattern.matcher(name).matches();
                if (looksLikeSource || resourceProxy.getType() == IResource.FOLDER) {
                    IResource resource = resourceProxy.requestResource();
                    if (resource != null && !resource.isSynchronized(IResource.DEPTH_ZERO))
                        unsynchronizedResources.add(resource.getProjectRelativePath());
                }
                return resourceProxy.getType() == IResource.FOLDER
                        || resourceProxy.getType() == IResource.PROJECT;
            }
        };

        try {
            project.accept(visitor, 0);
            if (unsynchronizedResources.size() == 0)
                return true;
        } catch (CoreException e1) {
            SourceGenPlugin.getDefault().log(e1);
            // fall through, something bad happened
        }

        Shell shell = null;
        boolean doSync = MessageDialog.openConfirm(shell,
                Messages.getString("SourceGenProvider.ProjectOutOfSync"), //$NON-NLS-1$
                MessageFormat.format(Messages.getString("SourceGenProvider.ProjectOutOfSyncMessage"), //$NON-NLS-1$
                        new Object[] { project.getName(),
                                TextUtils.formatTabbedList(unsynchronizedResources) }));
        if (doSync) {
            try {
                project.refreshLocal(IResource.DEPTH_INFINITE, null);
                return true;
            } catch (CoreException e) {
                SourceGenPlugin.getDefault().log(e);
                Logging.showErrorDialog(Messages.getString("SourceGenProvider.Error"), //$NON-NLS-1$
                        null, e.getStatus());
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}

From source file:com.nokia.sdt.symbian.ui.images.SingleURIImagePropertyEditorPane.java

License:Open Source License

/**
 * @param modelPath//  www  . j  a  v a2s.c o  m
 * @param exception
 */
protected boolean reportFailedCommit(IPath modelPath) {
    String msg;
    msg = MessageFormat.format(Messages.getString("SingleURIImagePropertyEditorPane.FailedToSaveMessage"), //$NON-NLS-1$
            new Object[] { modelPath });
    return MessageDialog.openConfirm(getShell(),
            Messages.getString("SingleURIImagePropertyEditorPane.FailedToSaveTitle"), //$NON-NLS-1$
            msg);
}

From source file:com.nokia.tools.s60.editor.ContentEditorPart.java

License:Open Source License

@Override
protected void performSave(IProgressMonitor monitor) {
    for (GraphicsEditorPart gep : getDirtyGraphicsEditors()) {
        if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                EditorMessages.GraphicsEditor_SavingConfirmation_Label,
                MessageFormat.format(EditorMessages.Editor_SaveGraphicsEditorConfirmation,
                        new Object[] { gep.getPartName() }))) {
            gep.doSave(monitor);//  ww  w  . j  av a  2s .c o  m
        }
    }

    try {
        mediator.saveContents(monitor);
        getProject().refreshLocal(IProject.DEPTH_INFINITE, monitor);

        // force dependent view to refresh - 'null' means that unknown
        // object is modified,
        // thus all should be refreshed
        fireContentModified(new String[] { null });
    } catch (Exception e) {
        S60WorkspacePlugin.error(e);
        MessageDialog.openError(getSite().getShell(), EditorMessages.Error_Editor_Save, e.getMessage());
    }
}

From source file:com.nokia.tools.s60.editor.Series60EditorPart.java

License:Open Source License

public void partActivated(IWorkbenchPart part) {
    try {/*from   w w w.  jav a 2  s. co  m*/
        activatePart(part);

        if (!cancelledNotification && part == this) {
            synchronized (this) {
                if (!cancelledNotification) {
                    Theme activeTheme = ThemeUtil.getCurrentActiveTheme();
                    if (activeTheme instanceof S60Theme) {
                        Map<ThirdPartyIconWrapper, List<TPIconConflictEntry>> conflictingIconList = ThirdPartyIconManager
                                .getConflictingIconList((S60Theme) activeTheme);
                        if (!conflictingIconList.isEmpty()) {
                            boolean confirmed = MessageDialog.openConfirm(part.getSite().getShell(),
                                    "Third Party Icons Conflicts",
                                    "Third party icon definitions for the current theme has conflicts. Resolve them now?");

                            if (confirmed) {
                                if (IDialogConstants.CANCEL_ID == showThirdPartyIconPage())
                                    cancelledNotification = true;
                            } else {
                                cancelledNotification = true;
                            }
                        }
                    }
                }
            }
        }

    } catch (RuntimeException e) {

        e.printStackTrace();
    }
}

From source file:com.nokia.tools.s60.preferences.PluginHandlingPreferencePage.java

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (e.getSource() == btnAdd) {
        PluginInstallationDialog pluginInstallationDialog = new PluginInstallationDialog(shell);
        if (Window.OK == pluginInstallationDialog.open()) {
            pluginViewer.refresh();/*from   w  w w .j a  v a 2  s.c  o  m*/
            setSystemPluginsGrayed();
            Bundle newEntry = pluginInstallationDialog.getBundle();
            if (newEntry != null) {
                pluginViewer.setSelection(new StructuredSelection(newEntry), true);
            }
        }
    }
    if (e.getSource() == btnRemove) {
        ISelection selection = pluginViewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            Bundle bundle = (Bundle) ((IStructuredSelection) selection).getFirstElement();
            IEditorReference[] editorsToClose = getEditorsToClose(bundle);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < editorsToClose.length; i++) {
                try {
                    IEditorInput input = editorsToClose[i].getEditorInput();
                    String name;
                    if (input instanceof IFileEditorInput) {
                        name = ((IFileEditorInput) input).getFile().getProject().getName();
                    } else {
                        name = input.getName();
                    }
                    sb.append(name + ", ");
                } catch (Exception ex) {
                    S60WorkspacePlugin.error(ex);
                }
            }
            if (sb.length() > 0) {
                sb.delete(sb.length() - 2, sb.length());
            }
            if (MessageDialog.openConfirm(getShell(),
                    Messages.PluginHandlingPreferencePage_Uninstall_Confirm_Title,
                    sb.length() > 0
                            ? MessageFormat.format(
                                    Messages.PluginHandlingPreferencePage_Uninstall_Confirm_Message2,
                                    new Object[] { bundle.getSymbolicName(), sb.toString() })
                            : MessageFormat.format(
                                    Messages.PluginHandlingPreferencePage_Uninstall_Confirm_Message,
                                    new Object[] { bundle.getSymbolicName() }))) {
                for (IEditorReference ref : editorsToClose) {
                    ref.getEditor(false).doSave(null);
                }

                try {
                    new ProgressMonitorDialog(getShell()).run(true, false,
                            new UninstallPluginOperation(bundle));
                    pluginViewer.refresh();
                } catch (Exception ex) {
                    MessageDialogWithTextContent.openError(getShell(),
                            Messages.PluginHandlingPreferencePage_Uninstall_Error_Title,
                            Messages.PluginHandlingPreferencePage_Uninstall_Error_Message,
                            StringUtils.dumpThrowable(ex));
                }

                if (editorsToClose.length > 0) {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                            .closeEditors(editorsToClose, true);
                }
            }
        }
    }
}

From source file:com.nokia.tools.variant.editor.dialogs.SaveAsDialog.java

License:Open Source License

/**
 * Save data and close the dialog window
 *///w  w  w. j a  v a 2s . c  o  m

protected void okPressed() {
    projectDirString = projectDir.getText();
    commentsString = commentsText.getText();

    if (!validateProjectDir(projectDirString)) {
        MessageDialog.openError(projectDir.getShell(), "Wrong path specified",
                "Specified path \"" + projectDirString + "\" is not valid.");
    } else if (new Path(cpfFilePath).toOSString().equals(new Path(projectDirString).toOSString())) {
        MessageDialog.openError(projectDir.getShell(), "Save is not allowed",
                "CPF file can not be saved to specified location: \"" + projectDirString + "\".");
    } else {
        File file = new File(new Path(projectDirString).toOSString());
        File file2 = new File(new Path(projectDirString).removeLastSegments(1).toString());

        if (file.exists()) {
            if (MessageDialog.openConfirm(projectDir.getShell(), "Override file?",
                    "File \"" + file.getPath() + "\" already exists. Do you want to override it?")) {
                super.okPressed();
            }
        } else if (!file2.exists()) {
            if (MessageDialog.openConfirm(projectDir.getShell(), "Create new directory?",
                    "Directory \"" + file.getPath() + "\" does not exist. Do you want to create it?")) {
                super.okPressed();
            }
        } else {
            super.okPressed();
        }
    }
}

From source file:com.nokia.tools.vct.internal.common.secure.ui.actions.DeleteKeysAction.java

License:Open Source License

@Override
public void run() {
    Object[] keys = ((IStructuredSelection) viewer.getSelection()).toArray();
    Shell shell = viewer.getControl().getShell();

    if (MessageDialog.openConfirm(shell, "Keys Removal", "Are you sure?")) {
        try {//ww w. j  ava  2  s  . c o m
            viewer.getControl().setRedraw(false);
            for (Object obj : keys) {
                if (obj instanceof IKeyStoreEntry) {
                    try {
                        IKeyStoreEntry alias = (IKeyStoreEntry) obj;
                        SecurityCorePlugin.getKeyStoreManager().removeEntry(alias);
                    } catch (CoreException e) {
                        e.printStackTrace();
                    }
                }
            }
        } finally {
            viewer.getControl().setRedraw(true);
        }
    }
}

From source file:com.nokia.traceviewer.view.TraceViewerView.java

License:Open Source License

public boolean showConfirmationDialog(String message) {
    boolean ok = MessageDialog.openConfirm(getShell(), TRACE_VIEWER_TITLE, message);
    return ok;
}