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.archimatetool.editor.model.impl.EditorModelManager.java

License:Open Source License

/**
 * Ask user for file name to save model//from  w  w  w . j av a 2 s .c  o m
 * @return the file or null
 */
private File askSaveModel() {
    // On Mac if the app is minimised in the dock Display.getCurrent().getActiveShell() will return null
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    shell.setActive(); // Get focus on Mac

    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    dialog.setFilterExtensions(new String[] { ARCHIMATE_FILE_WILDCARD, "*.*" }); //$NON-NLS-1$
    String path = dialog.open();
    if (path == null) {
        return null;
    }

    // Only Windows adds the extension by default
    if (dialog.getFilterIndex() == 0 && !path.endsWith(ARCHIMATE_FILE_EXTENSION)) {
        path += ARCHIMATE_FILE_EXTENSION;
    }

    File file = new File(path);

    // Make sure we don't already have it open
    for (IArchimateModel m : getModels()) {
        if (file.equals(m.getFile())) {
            MessageDialog.openWarning(shell, Messages.EditorModelManager_8,
                    NLS.bind(Messages.EditorModelManager_9, file));
            return null;
        }
    }

    // Make sure the file does not already exist
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(shell, Messages.EditorModelManager_10,
                NLS.bind(Messages.EditorModelManager_11, file));
        if (!result) {
            return null;
        }
    }

    return file;
}

From source file:com.archimatetool.editor.preferences.ColoursFontsPreferencePage.java

License:Open Source License

/**
 * @throws IOException//from   w w w  .j  a v  a 2s.c o m
 * Export a user color scheme
 */
private void exportUserColors() throws IOException {
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(Messages.ColoursFontsPreferencePage_5);
    dialog.setFileName("ArchiColours.prefs"); //$NON-NLS-1$
    String path = dialog.open();
    if (path == null) {
        return;
    }

    // Make sure the file does not already exist
    File file = new File(path);
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(getShell(), Messages.ColoursFontsPreferencePage_15,
                NLS.bind(Messages.ColoursFontsPreferencePage_16, file));
        if (!result) {
            return;
        }
    }

    PreferenceStore store = new PreferenceStore(path);
    saveColors(store);
    store.save();
}

From source file:com.archimatetool.editor.views.tree.actions.DeleteAction.java

License:Open Source License

@Override
public void run() {
    IStructuredSelection selection = getSelection();
    if (selection == null || selection.isEmpty()) {
        return;/*from  w  ww.j  ava  2s.  c  o m*/
    }

    DeleteCommandHandler cmdHandler = new DeleteCommandHandler((TreeModelViewer) getSelectionProvider(),
            selection.toArray());

    /*
     * If the objects are referenced in a diagram warn user
     */
    if (cmdHandler.hasDiagramReferences()) {
        if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteAction_1,
                Messages.DeleteAction_2 + "\n\n" + //$NON-NLS-1$
                        Messages.DeleteAction_3)) {
            return;
        }
    }

    cmdHandler.delete();
}

From source file:com.archimatetool.editor.WorkbenchCleaner.java

License:Open Source License

/**
 * Ask user if they want to reset the workbench.
 * If they do, create a marker file and restart.
 *///from   www .  ja va2s  .  c o m
public static void reset() {
    boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
            Messages.WorkbenchCleaner_0, Messages.WorkbenchCleaner_1);
    if (!result) {
        return;
    }

    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc != null) {
        try {
            if (PlatformUI.getWorkbench().restart()) { // User might have cancelled on a dirty editor
                File resetFile = new File(instanceLoc.getURL().getPath(), RESET_FILE);
                resetFile.createNewFile();
            }
        } catch (Exception ex) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.WorkbenchCleaner_2,
                    ex.getMessage());
            ex.printStackTrace();
        }
    }
}

From source file:com.archimatetool.example.MyExporter.java

License:Open Source License

/**
 * Ask user for file name to save to/*from w  w w.  j  av  a2 s.  c  om*/
 */
private File askSaveFile() {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setText(Messages.MyExporter_0);
    dialog.setFilterExtensions(new String[] { MY_EXTENSION_WILDCARD, "*.*" }); //$NON-NLS-1$
    String path = dialog.open();
    if (path == null) {
        return null;
    }

    // Only Windows adds the extension by default
    if (dialog.getFilterIndex() == 0 && !path.endsWith(MY_EXTENSION)) {
        path += MY_EXTENSION;
    }

    File file = new File(path);

    // Make sure the file does not already exist
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
                Messages.MyExporter_0, NLS.bind(Messages.MyExporter_1, file));
        if (!result) {
            return null;
        }
    }

    return file;
}

From source file:com.archimatetool.owlexchange.OWLExchangeExportProvider.java

License:Open Source License

/**
 * Ask user for file name to save to/*from  w ww . j  ava2 s.  c o m*/
 */
private File askSaveFile() {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setText("Export Model");
    dialog.setFilterExtensions(new String[] { FILE_EXTENSION_WILDCARD, "*.*" });
    String path = dialog.open();
    if (path == null) {
        return null;
    }

    // Only Windows adds the extension by default
    if (dialog.getFilterIndex() == 0 && !path.endsWith(FILE_EXTENSION)) {
        path += FILE_EXTENSION;
    }

    File file = new File(path);

    // Make sure the file does not already exist
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "Export Model",
                "'" + file + "' already exists. Are you sure you want to overwrite it?");
        if (!result) {
            return null;
        }
    }

    return file;
}

From source file:com.archimatetool.reports.html.HTMLReportExporter.java

License:Open Source License

private File askSaveFolder() {
    DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell());
    dialog.setText(Messages.HTMLReportExporter_24);
    dialog.setMessage(Messages.HTMLReportExporter_25);
    String path = dialog.open();//from w w w . j  a va2  s  .  co m
    if (path == null) {
        return null;
    }

    File folder = new File(path);
    if (folder.exists()) {
        String[] children = folder.list();
        if (children != null && children.length > 0) {
            boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
                    Messages.HTMLReportExporter_26, NLS.bind(Messages.HTMLReportExporter_27, folder));
            if (!result) {
                return null;
            }
        }
    } else {
        folder.mkdirs();
    }

    return folder;
}

From source file:com.archimatetool.templates.impl.wizard.SaveArchimateModelAsTemplateWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    // This before the thread starts
    fZipFile = new File(fPage1.getFileName());

    // Make sure the file does not already exist
    if (fZipFile.exists()) {
        boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
                Messages.SaveArchimateModelAsTemplateWizard_1,
                NLS.bind(Messages.SaveArchimateModelAsTemplateWizard_2, fZipFile.getPath()));
        if (!result) {
            return false;
        }/*  w  w w.j  av a2 s .  c o m*/
    }

    fTemplateName = fPage1.getTemplateName();
    fTemplateDescription = fPage1.getTemplateDescription();
    fIncludeThumbnails = fPage1.includeThumbnails();
    fSelectedDiagramModel = fPage1.getSelectedDiagramModel();
    fDoStoreInCollection = fPage2.doStoreInCollection();
    fSelectedTemplateGroup = fPage2.getTemplateGroup();

    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
        @Override
        public void run() {
            try {
                createZipFile(fZipFile);

                if (fDoStoreInCollection) {
                    fTemplateManager.addTemplateEntry(fZipFile, fSelectedTemplateGroup);
                }
            } catch (final IOException ex) {
                ex.printStackTrace();
                Display.getCurrent().asyncExec(new Runnable() { // Display after wizard closes
                    public void run() {
                        MessageDialog.openError(getShell(), Messages.SaveArchimateModelAsTemplateWizard_3,
                                ex.getMessage());
                    }
                });
            }
        }
    });

    return true;
}

From source file:com.arm.cmsis.pack.installer.jobs.CpPackInstallJob.java

License:Open Source License

@Override
protected IStatus run(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    progress.beginTask(NLS.bind(Messages.CpPackInstallJob_InstallingPack, fPackId), 100);

    boolean tryAgain = true;
    while (tryAgain) {
        try {//from   w  ww  . j  a v  a  2  s. c  o m
            File downloadFile = fPackInstaller.getRepoServiceProvider().getPackFile(fPackUrl, fPackDestFile,
                    progress.newChild(90));
            if (downloadFile != null) {
                ICpPack pack = unzipAndParse(downloadFile, progress.newChild(10));

                if (pack != null) {
                    fResult.setPack(pack);
                    fResult.setSuccess(true);
                } else {
                    downloadFile.delete();
                }
            }
            tryAgain = false;

        } catch (MalformedURLException e) {
            fResult.setErrorString(Messages.CpPackInstallJob_MalformedURL + fPackUrl);
            return Status.CANCEL_STATUS;
        } catch (SocketTimeoutException | UnknownHostException e) {
            Display.getDefault().syncExec(new Runnable() {
                @Override
                public void run() {
                    wait = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
                            Messages.CpPackInstaller_Timout,
                            NLS.bind(Messages.CpPackInstaller_TimeoutMessage, fPackUrl));
                }
            });
            if (!wait) {
                fResult.setErrorString(
                        NLS.bind(Messages.CpPackInstallJob_TimeoutConsoleMessage, fPackId, fPackUrl));
                return Status.CANCEL_STATUS;
            }
            continue;
        } catch (IOException e) {
            fResult.setErrorString(NLS.bind(Messages.CpPackInstallJob_FileNotFound, fPackUrl));
            return Status.CANCEL_STATUS;
        } catch (Exception e) {
            fResult.setErrorString(e.getMessage());
            return Status.CANCEL_STATUS;
        } finally {
            fPackInstaller.jobFinished(fPackId, RteEvent.PACK_INSTALL_JOB_FINISHED, fResult);
        }
    }

    return Status.OK_STATUS;
}

From source file:com.arm.cmsis.pack.installer.ui.CpInstallerPlugInUI.java

License:Open Source License

private void registerWorkbenchListener() {
    IWorkbench wb = PlatformUI.getWorkbench();
    if (wb == null) {
        return;/*from ww w .java2s  .  com*/
    }
    final ICpPackInstaller packInstaller = CpPlugIn.getPackManager().getPackInstaller();
    workbenchListener = new IWorkbenchListener() {
        @Override
        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            if (packInstaller.isBusy()) {
                boolean exit = MessageDialog.openQuestion(Display.getDefault().getActiveShell(),
                        Messages.CpInstallerPlugInUI_ExitEclipse,
                        Messages.CpInstallerPlugInUI_ExitEclipseMessage);
                if (exit) {
                    packInstaller.reset();
                    try {
                        Thread.sleep(500); // wait for the cancel
                    } catch (InterruptedException e) {
                        // ignore the exception
                    }
                }
                return exit;
            }
            return true;
        }

        @Override
        public void postShutdown(IWorkbench workbench) {
            // does nothing
        }
    };
    wb.addWorkbenchListener(workbenchListener);
}