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

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

Introduction

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

Prototype

public static boolean open(int kind, Shell parent, String title, String message, int style) 

Source Link

Document

Convenience method to open a simple dialog as specified by the kind flag.

Usage

From source file:edu.harvard.i2b2.eclipse.plugins.querytool.ui.utils.UIUtils.java

License:Open Source License

public static void popupMessage(final String title, final String message) {
    Display.getCurrent().syncExec(new Runnable() {
        public void run() {
            MessageDialog.open(MessageDialog.INFORMATION,
                    QueryToolViewAccessor.getInstance().getQueryToolView().getWorkbenchShell(), title, message,
                    SWT.NONE);//  w ww.ja  v  a  2 s.  c o m
        }
    });
}

From source file:eu.numberfour.n4js.ui.dialog.ModuleSpecifierSelectionDialog.java

License:Open Source License

/**
 * Processes the initial string selection.
 *
 * For existing resources it just sets the initial selection to the specified file system resource.
 *
 * In the case that the initial module specifier points to a non-existing location, a dialog is displayed which
 * allows the user to automatically create not yet existing folders.
 *
 * @param initialModuleSpecifier//from   ww w  .j av a  2  s . co m
 *            The module specifier
 * @return A {@link IWorkbenchAdapter} adaptable object or null on failure
 */
private Object processInitialSelection(String initialModuleSpecifier) {

    IPath sourceFolderPath = sourceFolder.getFullPath();
    IPath initialModulePath = new Path(initialModuleSpecifier);

    // Use the root element source folder for an empty initial selection
    if (initialModuleSpecifier.isEmpty()) {
        return this.sourceFolder;
    }

    // Use the root element source folder for invalid module specifiers
    if (!WorkspaceWizardValidatorUtils.isValidFolderPath(initialModulePath)) {
        return this.sourceFolder;
    }

    // The project relative path of a module specifier
    IPath fullPath = sourceFolderPath.append(new Path(initialModuleSpecifier));

    // If the module specifier refers to an existing n4js resource
    if (!fullPath.hasTrailingSeparator()) {
        IFile n4jsModuleFile = workspaceRoot
                .getFile(fullPath.addFileExtension(N4JSGlobals.N4JS_FILE_EXTENSION));
        IFile n4jsdModuleFile = workspaceRoot
                .getFile(fullPath.addFileExtension(N4JSGlobals.N4JSD_FILE_EXTENSION));

        // Just use it as initial selection
        if (n4jsModuleFile.exists()) {
            return n4jsModuleFile;
        }
        if (n4jsdModuleFile.exists()) {
            return n4jsdModuleFile;
        }

    }

    //// Otherwise use the existing part of the path as initial selection:

    // If the module specifier specifies the module name, extract it and remove its segment.
    if (isModuleFileSpecifier(initialModulePath)) {
        initialModuleName = initialModulePath.lastSegment();
        initialModulePath = initialModulePath.removeLastSegments(1);
    }

    IResource selection = this.sourceFolder;

    // Accumulate path segments to search for the longest existing path
    IPath accumulatedPath = sourceFolderPath;

    // Collect the paths of all non-existing segments
    // These are relative to the last existing segment of the path
    List<IPath> nonExistingSegmentPaths = new ArrayList<>();

    for (Iterator<String> segmentIterator = Arrays.asList(initialModulePath.segments())
            .iterator(); segmentIterator.hasNext(); /**/) {

        accumulatedPath = accumulatedPath.append(segmentIterator.next());

        // Results in null if non-existing
        IResource nextSegmentResource = workspaceRoot.findMember(accumulatedPath);

        // If the current segment is an existing file and not the last specifier segment
        // show a file overlap error message
        if (null != nextSegmentResource && !(nextSegmentResource instanceof IContainer)
                && segmentIterator.hasNext()) {

            MessageDialog.open(MessageDialog.ERROR, getShell(), SPECIFIER_OVERLAPS_WITH_FILE_TITLE, String
                    .format(SPECIFIER_OVERLAPS_WITH_FILE_MESSAGE, initialModuleSpecifier, accumulatedPath),
                    SWT.NONE);

            return selection;
        }

        // If the segment exist go ahead with the next one
        if (null != nextSegmentResource && nextSegmentResource.exists()) {
            selection = nextSegmentResource;
        } else { // If not add it to the list of non existing segments.
            nonExistingSegmentPaths.add(accumulatedPath.makeRelativeTo(selection.getFullPath()));
        }
    }

    // If any non-existing folders need to be created
    if (nonExistingSegmentPaths.size() > 0) {
        // Ask the user if he wants to create the missing folders
        boolean create = MessageDialog.open(MessageDialog.QUESTION, getShell(),
                NON_EXISTING_MODULE_LOCATION_TITLE, NON_EXISTING_MODULE_LOCATION_MESSAGE, SWT.NONE);

        // Create the missing folders
        if (create) {
            ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell());
            progressMonitorDialog.open();
            IProgressMonitor progressMonitor = progressMonitorDialog.getProgressMonitor();

            IPath deepestPath = nonExistingSegmentPaths.get(nonExistingSegmentPaths.size() - 1);
            selection = createFolderPath(deepestPath, (IContainer) selection, progressMonitor);

            progressMonitor.done();
            progressMonitorDialog.close();
        }

    }
    return selection;
}

From source file:eu.numberfour.n4js.ui.dialog.ModuleSpecifierSelectionDialog.java

License:Open Source License

/**
 * Creates all non-existing segments of the given path.
 *
 * @param path/*w w  w.ja v a2s .c  o  m*/
 *            The path to create
 * @param parent
 *            The container in which the path should be created in
 * @param monitor
 *            A progress monitor. May be {@code null}
 *
 * @return The folder specified by the path
 */
private IContainer createFolderPath(IPath path, IContainer parent, IProgressMonitor monitor) {
    IContainer activeContainer = parent;

    if (null != monitor) {
        monitor.beginTask("Creating folders", path.segmentCount());
    }

    for (String segment : path.segments()) {
        IFolder folderToCreate = activeContainer.getFolder(new Path(segment));
        try {
            if (!folderToCreate.exists()) {
                createFolder(segment, activeContainer, monitor);
            }
            if (null != monitor) {
                monitor.worked(1);
            }
            activeContainer = folderToCreate;
        } catch (CoreException e) {
            LOGGER.error("Failed to create module folders.", e);
            MessageDialog.open(MessageDialog.ERROR, getShell(), FAILED_TO_CREATE_FOLDER_TITLE,
                    String.format(FAILED_TO_CREATE_FOLDER_MESSAGE, folderToCreate.getFullPath().toString(),
                            e.getMessage()),
                    SWT.NONE);
            break;
        }
    }
    return activeContainer;
}

From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java

License:Open Source License

/**
 * Display an error dialog with the specified message.
 *//*from   w  w w .  j  ava2s  .  c  om*/
private void displayErrorDialog(String message) {
    MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), getErrorDialogTitle(), message,
            SWT.SHEET);
}

From source file:eu.numberfour.n4js.ui.handler.CreateNewN4JSElementInModuleHandler.java

License:Open Source License

/**
 * Opens the wizard with the given id and passes it the selection.
 *
 * @param wizardId/*w w  w  . j a  v  a 2 s . c  om*/
 *            The wizard id of the eclipse newWizard registry
 * @param selection
 *            The selection
 */
private void openWizardForModule(String wizardId, IStructuredSelection selection, boolean nested) {

    // Retrieve wizard from registry
    IWizardDescriptor wizardDescriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(wizardId);

    if (wizardDescriptor == null) {
        return;
    }

    try {
        IWorkbenchWizard wizard = wizardDescriptor.createWizard();

        // Inject wizard members
        injector.injectMembers(wizard);

        // Create and open a new wizard dialog
        WizardDialog wizardDialog = new WizardDialog(UIUtils.getShell(), wizard);

        // If the wizard supports it, enable in module option
        if (wizard instanceof N4JSNewClassifierWizard<?>) {
            ((N4JSNewClassifierWizard<?>) wizard).init(PlatformUI.getWorkbench(), selection, nested);
        } else {
            // Otherwise just pass it the initial selection
            wizard.init(PlatformUI.getWorkbench(), selection);
        }

        // wizardDialog.setTitle(wizard.getWindowTitle());
        wizardDialog.open();

    } catch (CoreException e) {
        /** Failed to create the wizard */
        Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        MessageDialog.open(MessageDialog.ERROR, workbenchShell, "Failed to launch wizard",
                String.format("Failed to launch wizard %s", wizardId), SWT.SHEET);
        return;
    }

}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.CheckConnectionHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String message = "";
    try {/*from   w w w.j a v  a 2  s . c  o  m*/
        message = checkConnection();
    } catch (ClientProtocolException e) {
        message += e.getMessage();
        e.printStackTrace();
    } catch (IOException e) {
        message += e.getMessage();
        e.printStackTrace();
    }
    MessageDialog.open(MessageDialog.INFORMATION, HandlerUtil.getActiveShell(event), "Connection check result",
            message, SWT.SHEET);
    return null;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.RetrieveSEEHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {//from w  ww . j a va  2s.c  om
        if (SkillproService.getSkillproProvider().getSEERepo().isEmpty()) {
            getAllSEE();
        } else {
            getNewSEE();
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception",
                e.getMessage(), SWT.SHEET);
    } catch (IOException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception",
                e.getMessage(), SWT.SHEET);
    }
    return null;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.UpdateRegisteredSEEsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {/*  ww w  . j  ava 2s  .com*/
        List<SEE> registeredSEEs = new ArrayList<>();
        for (SEE see : SkillproService.getSkillproProvider().getSEERepo()) {
            if (see.getMESNodeID() != null || !see.getMESNodeID().isEmpty()) {
                registeredSEEs.add(see);
            }
        }
        //can actually be done in the first for-loop, but let's just leave it like this for now
        for (SEE see : registeredSEEs) {
            updateSEE(see);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception",
                e.getMessage(), SWT.SHEET);
    } catch (IOException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception",
                e.getMessage(), SWT.SHEET);
    }
    return null;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.WipeResourceExecutableSkillsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {/*from   w ww.  ja  v  a2 s .co m*/
        Report report = wipeWipeWipe();
        MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                SWT.ICON_QUESTION | SWT.OK);
        messageBox.setText("Wiping Resource Executable Skills");
        messageBox.setMessage(report.message);
        messageBox.open();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception",
                e.getMessage(), SWT.SHEET);
    } catch (IOException e) {
        e.printStackTrace();
        MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception",
                e.getMessage(), SWT.SHEET);
    }
    return null;
}

From source file:gov.nasa.ensemble.common.ui.WidgetUtils.java

License:Open Source License

/**
 * Pop up a message asynchronously.  Recommended for calling from wizard performFinish methods.
 * @param kind -- e.g. MessageDialog.WARNING
 * @param title/*from  w  w  w.  j  av a 2 s . co  m*/
 * @param message
 */
public static void delayedMessage(final int kind, final String title, final String message) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // ignore
            }
            WidgetUtils.runLaterInDisplayThread(getShell(), new Runnable() {
                @Override
                public void run() {
                    MessageDialog.open(kind, getShell(), title, message, SWT.NONE);
                }
            });
        }
    }).start();
}