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:com.aptana.rcp.DelayedEventsProcessor.java

License:Open Source License

private void openFile(Display display, final String path) {
    display.asyncExec(new Runnable() {
        public void run() {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window == null)
                return;
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
            IFileInfo fetchInfo = fileStore.fetchInfo();
            if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
                IWorkbenchPage page = window.getActivePage();
                if (page == null) {
                    String msg = NLS.bind(IDEWorkbenchMessages.OpenDelayedFileAction_message_noWindow, path);
                    MessageDialog.open(MessageDialog.ERROR, window.getShell(),
                            IDEWorkbenchMessages.OpenDelayedFileAction_title, msg, SWT.SHEET);
                }/*from  w w w .j a v  a2  s .  c  o  m*/
                try {
                    IDE.openInternalEditorOnFileStore(page, fileStore);
                    Shell shell = window.getShell();
                    if (shell != null) {
                        if (shell.getMinimized())
                            shell.setMinimized(false);
                        shell.forceActive();
                    }
                } catch (PartInitException e) {
                    String msg = NLS.bind(IDEWorkbenchMessages.OpenDelayedFileAction_message_errorOnOpen,
                            fileStore.getName());
                    CoreException eLog = new PartInitException(e.getMessage());
                    IDEWorkbenchPlugin.log(msg, new Status(IStatus.ERROR, IDEApplication.PLUGIN_ID, msg, eLog));
                    MessageDialog.open(MessageDialog.ERROR, window.getShell(),
                            IDEWorkbenchMessages.OpenDelayedFileAction_title, msg, SWT.SHEET);
                }
            } else {
                String msg = NLS.bind(IDEWorkbenchMessages.OpenDelayedFileAction_message_fileNotFound, path);
                MessageDialog.open(MessageDialog.ERROR, window.getShell(),
                        IDEWorkbenchMessages.OpenDelayedFileAction_title, msg, SWT.SHEET);
            }
        }
    });
}

From source file:com.aptana.ui.util.UIUtils.java

License:Open Source License

/**
 * Schedules a message dialog to be displayed safely in the UI thread
 * /*from   w w w .j  ava 2s.c  o  m*/
 * @param kind
 *            MessageDialog constants indicating the kind
 * @param title
 *            MessageDialog title
 * @param message
 *            MessageDialog message
 * @param runnable
 *            Something that gets run if the message dialog return code is Window.OK
 */
public static void showMessageDialogFromBgThread(final int kind, final String title, final String message,
        final ISafeRunnable runnable) {
    showMessageDialogFromBgThread(new SafeMessageDialogRunnable() {

        public void run() throws Exception {
            if (runnable != null) {
                runnable.run();
            }
        }

        public int openMessageDialog() {
            if (kind == MessageDialog.INFORMATION) {
                // for info messages, we show the toast popup
                GenericInfoPopupDialog dialog = new GenericInfoPopupDialog(
                        UIUtils.getActiveWorkbenchWindow().getShell(), title, message);
                return dialog.open();
            }
            return MessageDialog.open(kind, UIUtils.getActiveWorkbenchWindow().getShell(), title, message,
                    SWT.NONE) ? Window.OK : Window.CANCEL;
        }
    }, Window.OK);
}

From source file:com.baremetalstudios.mapleide.datatransfer.ArchiveFileManipulations.java

License:Open Source License

/**
 * Display an error dialog with the specified message.
 * //from  ww  w. j  av  a2s .  com
 * @param message
 *            the error message
 */
protected static void displayErrorDialog(String message, Shell shell) {
    MessageDialog.open(MessageDialog.ERROR, shell, getErrorDialogTitle(), message, SWT.SHEET);
}

From source file:com.conwet.wirecloud.ide.wizards.WizardProjectsImportPage.java

License:Open Source License

/**
 * Display an error dialog with the specified message.
 *
 * @param message/*w  ww  .j av  a 2s  . c om*/
 *       the error message
 */
protected void displayErrorDialog(String message) {
    MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), getErrorDialogTitle(), message,
            SWT.SHEET);
}

From source file:com.coretek.testcase.projectView.projectwizard.page.WizardNewFolderMainPage.java

License:Open Source License

/**
 * Creates a new folder resource in the selected container and with the
 * selected name. Creates any missing resource containers along the path;
 * does nothing if the container resources already exist.
 * <p>// ww  w  .j  av a 2  s  .  co  m
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new folder once it has been successfully
 * created; subsequent invocations of this method will answer the same
 * folder resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 * 
 * @return the created folder resource, or <code>null</code> if the folder
 *         was not created
 */
public IFolder createNewFolder() {
    if (newFolder != null) {
        return newFolder;
    }

    // create the new folder and cache it if successful
    final IPath containerPath = resourceGroup.getContainerFullPath();
    IPath newFolderPath = containerPath.append(resourceGroup.getResource());
    final IFolder newFolderHandle = createFolderHandle(newFolderPath);

    createLinkTarget();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            CreateFolderOperation op = new CreateFolderOperation(newFolderHandle, linkTargetPath,
                    IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
            try {
                // see bug
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved. Making this undoable can result in
                // accidental
                // folder (and file) deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), // Was
                                    // Utilities.getFocusShell()
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_errorTitle, null, // no
                                    // special
                                    // message
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getCause()); //$NON-NLS-1$
                            MessageDialog.openError(getContainer().getShell(),
                                    IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                                    NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                                            e.getCause().getMessage()));
                        }
                    }
                });
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                        e.getTargetException().getMessage()),
                SWT.SHEET);
        return null;
    }

    newFolder = newFolderHandle;

    return newFolder;
}

From source file:com.google.dart.tools.deploy.DelayedEventsProcessor.java

License:Open Source License

private void openFile(Display display, final String path) {
    display.asyncExec(new Runnable() {
        @Override//from   ww  w  . j  av a 2 s. c o  m
        public void run() {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window == null) {
                return;
            }
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
            IFileInfo fetchInfo = fileStore.fetchInfo();
            if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
                IWorkbenchPage page = window.getActivePage();
                if (page == null) {

                    // TODO: Add a more robust way of displaying error messages at this point. Maybe a read
                    // only editor page like the Welcome editor so that users can get to the information.

                    String msg = NLS.bind("The file ''{0}'' could not be opened.", path);
                    MessageDialog.open(MessageDialog.ERROR, window.getShell(), "Open File", msg, SWT.SHEET);
                }
                try {
                    IDE.openInternalEditorOnFileStore(page, fileStore);
                    IWorkbenchPartReference partRef = page.getActivePartReference();
                    if (partRef != null) {
                        if (!page.isPageZoomed()) {
                            page.toggleZoom(partRef);
                        }
                    }
                    Shell shell = window.getShell();
                    if (shell != null) {
                        if (shell.getMinimized()) {
                            shell.setMinimized(false);
                        }
                        shell.forceActive();
                    } else {
                        throw new PartInitException("Shell could not be found");
                    }
                } catch (PartInitException e) {
                    String msg = NLS.bind("The file ''{0}'' could not be opened.\nSee log for details.",
                            fileStore.getName());
                    CoreException eLog = new PartInitException(e.getMessage());
                    Activator.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, msg, eLog));
                    MessageDialog.open(MessageDialog.ERROR, window.getShell(), "Open File", msg, SWT.SHEET);
                }
            } else {
                String msg = NLS.bind("The file ''{0}'' could not be found.", path);
                MessageDialog.open(MessageDialog.ERROR, window.getShell(), "Open File", msg, SWT.SHEET);
            }
        }
    });
}

From source file:com.google.dart.tools.ui.internal.projects.CreateApplicationWizard.java

License:Open Source License

private void createFolder(IPath path) {

    final ProjectType projectType = page.getProjectType();
    final boolean hasPubSupport = page.hasPubSupport();

    IPath containerPath = path.removeLastSegments(1);

    IResource container = ResourceUtil.getResource(containerPath.toFile());
    IPath newFolderPath = container.getFullPath().append(path.lastSegment());

    final IFolder newFolderHandle = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(newFolderPath);

    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override/* w ww . j a  va  2 s.co m*/
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            AbstractOperation op;
            op = new CreateFolderOperation(newFolderHandle, null,
                    IDEWorkbenchMessages.WizardNewFolderCreationPage_title);
            try {

                IStatus status = op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));

                if (status.isOK() && projectType != ProjectType.NONE) {
                    createdFile = createProjectContent(newProject, newFolderHandle.getLocation().toOSString(),
                            newFolderHandle.getName(), projectType, hasPubSupport);
                }

            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {

    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        IDEWorkbenchPlugin.log(getClass(), "createNewFolder()", e.getTargetException()); //$NON-NLS-1$
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(),
                IDEWorkbenchMessages.WizardNewFolderCreationPage_internalErrorTitle,
                NLS.bind(IDEWorkbenchMessages.WizardNewFolder_internalError,
                        e.getTargetException().getMessage()),
                SWT.SHEET);

    }

    newProject = newFolderHandle.getProject();

}

From source file:com.htmlhifive.tools.codeassist.ui.view.OptionConfigureComposite.java

License:Apache License

/**
 * ??./*from   w w w  . ja  v a  2s  .c o  m*/
 *
 * @throws CoreException ??.
 */
private void createComposite() throws CoreException {

    this.setLayoutData(new GridData(GridData.FILL_BOTH));
    this.setLayout(new GridLayout(1, false));
    // ??.
    Group optionGroup = new Group(this, SWT.None);
    optionGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    optionGroup.setText(UIMessages.UICL0001.getText());
    optionGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).extendedMargins(5, 5, 10, 5).create());

    // ?.
    Label optionPathLabel = new Label(optionGroup, SWT.None);
    GridData gdOptionPathLabel = new GridData();
    gdOptionPathLabel.horizontalSpan = 1;
    gdOptionPathLabel.grabExcessHorizontalSpace = false;
    gdOptionPathLabel.verticalAlignment = SWT.BEGINNING;
    optionPathLabel.setText(UIMessages.UICL0002.getText());
    optionPathLabel.setLayoutData(gdOptionPathLabel);

    // ??.
    optionPathText = new Text(optionGroup, SWT.BORDER);
    GridData gdText = new GridData(GridData.FILL_HORIZONTAL);
    gdText.horizontalSpan = 1;
    gdText.verticalAlignment = SWT.BEGINNING;
    optionPathText.setLayoutData(gdText);
    if (bean.getOptionFilePath() != null) {
        optionPathText.setText(bean.getOptionFilePath());
    }
    optionPathText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {

            updateBean();
        }

    });
    Composite btnCompsite = new Composite(optionGroup, SWT.None);
    btnCompsite.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 5).create());
    btnCompsite.setLayoutData(GridDataFactory.fillDefaults().create());

    Button btnSelect = new Button(btnCompsite, SWT.None);
    btnSelect.setText(UIMessages.UIBT0001.getText());
    btnSelect.setLayoutData(GridDataFactory.fillDefaults().hint(60, -1).create());

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

            FileSelectionDialog dialog = new FileSelectionDialog(getShell(), UIMessages.UIDT0001.getText(),
                    UIMessages.UIDM0001.getText(), new String[] { H5CodeAssistCorePluginConst.EXTENTION_XML });
            dialog.setInitialSelection(
                    ResourcesPlugin.getWorkspace().getRoot().findMember(optionPathText.getText()));
            if (dialog.open() == Window.OK) {
                IFile file = (IFile) dialog.getFirstResult();
                optionPathText.setText(file.getFullPath().toString());
                updateBean();
            }
        }
    });

    Button btnExport = new Button(this, SWT.None);
    btnExport.setText(UIMessages.UIBT0002.getText());
    btnExport.setLayoutData(GridDataFactory.swtDefaults().hint(-1, -1).create());
    btnExport.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SaveAsDialog dialog = new SaveAsDialog(getShell());
            dialog.setTitle(UIMessages.UIDT0003.getText());
            dialog.setHelpAvailable(false);
            dialog.setOriginalFile(getProject().getFile("h5-code-assist.xml"));
            if (dialog.open() == Window.OK) {
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(dialog.getResult());
                boolean fileExist = file.exists();
                InputStream is = H5CodeAssistCorePlugin.class.getClassLoader()
                        .getResourceAsStream("h5-code-assist.xml");
                try {
                    if (!fileExist) {
                        file.create(is, true, null);
                    } else {
                        file.setContents(is, IResource.DEPTH_INFINITE, null);
                    }
                    MessageDialog.open(MessageDialog.INFORMATION, getShell(), UIMessages.UIDT0004.getText(),
                            UIMessages.UIDM0002.format(file.getFullPath().toString()), SWT.None);
                } catch (CoreException e1) {
                    logger.log(UIMessages.UIEM0002, e1);
                    ErrorDialog.openError(getShell(), UIMessages.UIDT0002.getText(), e1.getMessage(),
                            e1.getStatus());
                } finally {
                    IOUtils.closeQuietly(is);
                }
            }

        }
    });

}

From source file:com.jaspersoft.studio.model.style.command.CreateStyleTemplateCommand.java

License:Open Source License

private void createObject() {
    if (jrTemplate == null) {
        FilteredResourcesSelectionDialog fd = new FilteredHelpDialog(Display.getCurrent().getActiveShell(),
                false, ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE);
        fd.setInitialPattern("*.jrtx");//$NON-NLS-1$
        if (fd.open() == Dialog.OK) {
            IFile file = (IFile) fd.getFirstResult();
            File fileToBeOpened = file.getRawLocation().makeAbsolute().toFile();
            boolean showErrorMessage = false;
            //Check if the file is a valid template before add it to the model
            if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
                try {
                    //Try to load the file to see if it is a valid template
                    JRXmlTemplateLoader.load(fileToBeOpened);
                    this.jrTemplate = MStyleTemplate.createJRTemplate();
                    JRDesignExpression jre = new JRDesignExpression();
                    jre.setText("\"" + getStylePath(file) + "\"");//$NON-NLS-1$ //$NON-NLS-2$
                    ((JRDesignReportTemplate) jrTemplate).setSourceExpression(jre);
                } catch (Exception ex) {
                    showErrorMessage = true;
                }/*from   w w  w  . j  ava2s . c  o  m*/
            } else {
                showErrorMessage = true;
            }
            if (showErrorMessage) {
                MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(),
                        Messages.UIUtils_ExceptionTitle, Messages.CreateStyleTemplateCommand_loadStyleError,
                        SWT.NONE);
            }
        }
    }
}

From source file:com.onpositive.mapper.actions.MergeAllLayersAction.java

License:Open Source License

protected void doPerformAction() {
    Map map = editor.getMap();/*from   w ww . ja  v  a 2  s. c om*/

    boolean result = MessageDialog.open(MessageDialog.QUESTION_WITH_CANCEL, editor.getEditorSite().getShell(),
            "Merge Tiles?", "Do you wish to merge tile images, and create a new tile set?", SWT.NONE);
    //        int ret = JOptionPane.showConfirmDialog(null,
    //                "Do you wish to merge tile images, and create a new tile set?",
    //                "Merge Tiles?", JOptionPane.YES_NO_CANCEL_OPTION);

    if (result) {
        TileMergeHelper tmh = new TileMergeHelper(map);
        int len = map.getTotalLayers();
        //TODO: Add a dialog option: "Yes, visible only"
        TileLayer newLayer = tmh.merge(0, len, true);
        map.removeAllLayers();
        map.addLayer(newLayer);
        newLayer.setName("Merged Layer");
        map.addTileset(tmh.getSet());
        editor.setCurrentLayer(0);
    } else /*if (ret == JOptionPane.NO_OPTION)*/ {
        while (map.getTotalLayers() > 1) {
            map.mergeLayerDown(editor.getCurrentLayerIndex());
        }
        editor.setCurrentLayer(0);
    }

}