Search in sources :

Example 56 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project portfolio by buchen.

the class CustomSaveHandler method promptToSave.

@Override
public Save promptToSave(MPart dirtyPart) {
    String prompt = MessageFormat.format(Messages.SaveHandlerPrompt, dirtyPart.getLabel());
    MessageDialog dialog = new PromptForSaveDialog(Display.getDefault().getActiveShell(), prompt);
    switch(dialog.open()) {
        case 0:
            return Save.YES;
        case 1:
            return Save.NO;
        case 2:
        default:
            return Save.CANCEL;
    }
}
Also used : MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 57 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project portfolio by buchen.

the class UpdateHelper method promptForRestart.

private void promptForRestart() {
    Display.getDefault().asyncExec(() -> {
        MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), Messages.LabelInfo, null, // 
        Messages.MsgRestartRequired, // 
        MessageDialog.INFORMATION, new String[] { Messages.BtnLabelRestartNow, Messages.BtnLabelRestartLater }, 0);
        int returnCode = dialog.open();
        if (returnCode == 0) {
            try {
                boolean successful = partService.saveAll(true);
                if (successful)
                    workbench.restart();
            } catch (IllegalStateException e) {
                PortfolioPlugin.log(e);
                MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, Messages.MsgCannotRestartBecauseOfOpenDialog);
            }
        }
    });
}
Also used : MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 58 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project InformationSystem by ObeoNetwork.

the class AbstractScaffoldHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    shell = HandlerUtil.getActiveShell(event);
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.size() == 2) {
            ScaffoldInfo existingScaffoldInfo = getExistingScaffoldModel(structuredSelection);
            if (existingScaffoldInfo != null) {
                MessageDialog dlg = new MessageDialog(shell, "Existing scaffold model found", null, "A scaffold model already exists for these objects in file " + existingScaffoldInfo.eResource().getURI().toPlatformString(true) + "\n\nWhat do you want to do ?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Use existing scaffold", "Create a new scaffold", "Cancel" }, 0);
                int btn = dlg.open();
                if (btn == CANCEL) {
                    return null;
                } else if (btn == CREATE_NEW_SCAFFOLD) {
                    executeScaffoldingWizard(structuredSelection);
                } else if (btn == USE_EXISTING_SCAFFOLD) {
                    executeFromScaffoldModel(existingScaffoldInfo);
                }
            } else {
                executeScaffoldingWizard(structuredSelection);
            }
        } else if (structuredSelection.size() == 1) {
            executeFromScaffoldModel(structuredSelection);
        }
    }
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ScaffoldInfo(fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 59 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project titan.EclipsePlug-ins by eclipse.

the class DecipheringPreferenceHandler method importFromFile.

/**
 * Imports all of the rulesets from the given file.
 * If a ruleset with the same name already exists, a dialog will be displayed to the user.
 *
 * @param file
 * @throws ImportFailedException
 */
public static void importFromFile(final File file) throws ImportFailedException {
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(file);
        final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
        InputSource inputSource = new InputSource(stream);
        Document document = builder.parse(inputSource);
        Element documentElement = document.getDocumentElement();
        if (!documentElement.getNodeName().contentEquals(TAG_ROOT)) {
            throw new ImportFailedException("The xml file is not valid");
        }
        final List<String> alreadyExistingRulesets = getAvailableRuleSets();
        NodeList rulesets = document.getElementsByTagName(TAG_RULE_SET);
        Boolean overwriteAll = null;
        for (int i = 0; i < rulesets.getLength(); ++i) {
            Element ruleElement = (Element) rulesets.item(i);
            NodeList nameList = ruleElement.getElementsByTagName(TAG_NAME);
            if (nameList.getLength() == 0) {
                throw new ImportFailedException("The ruleset's name is missing.");
            }
            final String rulesetName = nameList.item(0).getTextContent();
            if (rulesetName.length() == 0) {
                throw new ImportFailedException("The ruleset name can not be the empty string.");
            }
            NodeList messageTypeListList = ruleElement.getElementsByTagName(TAG_MSG_TYPE_LIST);
            if (messageTypeListList.getLength() == 0) {
                throw new ImportFailedException("The message type list for the ruleset '" + rulesetName + "' is missing.");
            }
            Element messageTypeListElement = (Element) messageTypeListList.item(0);
            NodeList msgTypeList = messageTypeListElement.getElementsByTagName(TAG_MSG_TYPE);
            Map<String, List<String>> msgTypesMap = importMessageTypes(rulesetName, msgTypeList);
            if (!alreadyExistingRulesets.contains(rulesetName)) {
                alreadyExistingRulesets.add(rulesetName);
                DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap);
                continue;
            }
            if (overwriteAll == null) {
                final MessageDialog msgdialog = new MessageDialog(null, "Ruleset exists", null, "The following ruleset already exists: " + rulesetName + ".\nOverwrite the existing ruleset?", MessageDialog.QUESTION, new String[] { "Yes", "No", "Yes to All", "No to All" }, 1);
                final int result = msgdialog.open();
                if (result == 2) {
                    overwriteAll = true;
                } else if (result == 3) {
                    overwriteAll = false;
                }
                if (result == 2 || result == 0) {
                    DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap);
                    alreadyExistingRulesets.add(rulesetName);
                }
            } else if (overwriteAll) {
                DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap);
                alreadyExistingRulesets.add(rulesetName);
            }
        }
        PreferencesHandler.getInstance().setImportLastDir(file.getParentFile().getPath());
    } catch (ParserConfigurationException e) {
        throw new ImportFailedException("Error while parsing the file: " + e.getMessage());
    } catch (SAXException e) {
        throw new ImportFailedException("Error while parsing the file: " + e.getMessage());
    } catch (IOException e) {
        throw new ImportFailedException("Error while parsing the file: " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 60 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project epp.mpc by eclipse.

the class MarketplaceWizardDialog method configureShell.

@Override
protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    // make jface dialog accessible for swtbot
    newShell.setData(this);
    new MarketplaceDropAdapter() {

        @Override
        protected void proceedInstallation(String url) {
            SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
            CatalogDescriptor catalogDescriptor = info.getCatalogDescriptor();
            String installItem = info.getInstallId();
            // we ignore previous wizard state here, since the wizard is still open...
            if (installItem != null && installItem.length() > 0) {
                info.setState(null);
                getWizard().handleInstallRequest(info, url);
            }
        }

        @Override
        protected void proceedFavorites(String url) {
            getWizard().importFavorites(url);
        }
    }.installDropTarget(newShell);
    final IWorkbenchListener workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            Shell wizardShell = wizardDialog.getShell();
            if (wizardShell != null && !wizardShell.isDisposed()) {
                if (!forced) {
                    MarketplaceWizard wizard = wizardDialog.getWizard();
                    boolean hasPendingActions = false;
                    IWizardPage currentPage = wizardDialog.getCurrentPage();
                    if (currentPage != null && wizard != null) {
                        if (currentPage == wizard.getCatalogPage()) {
                            hasPendingActions = !wizard.getSelectionModel().getSelectedCatalogItems().isEmpty();
                        } else {
                            hasPendingActions = true;
                        }
                    }
                    if (hasPendingActions) {
                        Shell parentShell = activate(wizardDialog.getShell());
                        MessageDialog messageDialog = new MessageDialog(parentShell, Messages.MarketplaceWizardDialog_PromptPendingActionsTitle, null, Messages.MarketplaceWizardDialog_PromptPendingActionsMessage, MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, SWT.NONE);
                        int result = messageDialog.open();
                        switch(result) {
                            case // yes
                            0:
                                finishWizard();
                                return false;
                            case // no
                            1:
                                break;
                            // cancel
                            case 3:
                            // [x]
                            case SWT.DEFAULT:
                            default:
                                return false;
                        }
                    }
                }
                if (forced) {
                    wizardShell.close();
                } else {
                    boolean closed = wizardDialog.close();
                    return closed;
                }
            }
            return true;
        }

        private void finishWizard() {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            MarketplaceWizard wizard = wizardDialog.getWizard();
            IWizardPage currentPage = wizardDialog.getCurrentPage();
            if (currentPage == wizard.getCatalogPage()) {
                ((MarketplacePage) currentPage).showNextPage();
            }
        }

        private Shell activate(Shell shell) {
            Shell activeShell = shell.getDisplay().getActiveShell();
            if (activeShell != shell) {
                Shell[] childShells = shell.getShells();
                if (childShells.length == 0 || !Arrays.asList(childShells).contains(activeShell)) {
                    shell.forceActive();
                    shell.forceFocus();
                }
            }
            if (activeShell == null) {
                activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
                if (activeShell == null) {
                    activeShell = shell;
                }
            }
            return activeShell;
        }

        public void postShutdown(IWorkbench workbench) {
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
    newShell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
        }
    });
    if (newShell.getParent() == null) {
        // bug 500379 - root shells don't handle escape traversal by default
        newShell.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                if (e.keyCode == SWT.ESC) {
                    Shell shell = (Shell) e.widget;
                    if (shell != null && !shell.isDisposed() && shell.isVisible() && shell.isEnabled()) {
                        shell.close();
                    }
                }
            }
        });
    }
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) DisposeListener(org.eclipse.swt.events.DisposeListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) IWizardPage(org.eclipse.jface.wizard.IWizardPage) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Aggregations

MessageDialog (org.eclipse.jface.dialogs.MessageDialog)129 Shell (org.eclipse.swt.widgets.Shell)27 CoreException (org.eclipse.core.runtime.CoreException)16 IPath (org.eclipse.core.runtime.IPath)14 File (java.io.File)10 ArrayList (java.util.ArrayList)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Composite (org.eclipse.swt.widgets.Composite)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Point (org.eclipse.swt.graphics.Point)7 IOException (java.io.IOException)6 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 List (java.util.List)5 IStatus (org.eclipse.core.runtime.IStatus)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 Path (org.eclipse.core.runtime.Path)4