Search in sources :

Example 11 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project dbeaver by serge-rider.

the class NavigatorHandlerObjectDelete method confirmObjectDelete.

private ConfirmResult confirmObjectDelete(final IWorkbenchWindow workbenchWindow, final DBNNode node, final boolean viewScript) {
    if (deleteAll != null) {
        return deleteAll ? ConfirmResult.YES : ConfirmResult.NO;
    }
    ResourceBundle bundle = DBeaverActivator.getCoreResourceBundle();
    String objectType = node instanceof DBNLocalFolder ? DBeaverPreferences.CONFIRM_LOCAL_FOLDER_DELETE : DBeaverPreferences.CONFIRM_ENTITY_DELETE;
    //$NON-NLS-1$
    String titleKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" + ConfirmationDialog.RES_KEY_TITLE;
    //$NON-NLS-1$
    String messageKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" + ConfirmationDialog.RES_KEY_MESSAGE;
    String nodeTypeName = node.getNodeType();
    MessageDialog dialog = new MessageDialog(workbenchWindow.getShell(), UIUtils.formatMessage(bundle.getString(titleKey), nodeTypeName, node.getNodeName()), DBeaverIcons.getImage(UIIcon.REJECT), UIUtils.formatMessage(bundle.getString(messageKey), nodeTypeName.toLowerCase(), node.getNodeName()), MessageDialog.CONFIRM, null, 0) {

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
            createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
            if (structSelection.size() > 1) {
                createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false);
                createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
            }
            if (viewScript) {
                createButton(parent, IDialogConstants.DETAILS_ID, CoreMessages.actions_navigator_view_script_button, false);
            }
        }
    };
    int result = dialog.open();
    switch(result) {
        case IDialogConstants.YES_ID:
            return ConfirmResult.YES;
        case IDialogConstants.YES_TO_ALL_ID:
            deleteAll = true;
            return ConfirmResult.YES;
        case IDialogConstants.NO_ID:
            return ConfirmResult.NO;
        case IDialogConstants.CANCEL_ID:
        case -1:
            deleteAll = false;
            return ConfirmResult.NO;
        case IDialogConstants.DETAILS_ID:
            return ConfirmResult.DETAILS;
        default:
            //$NON-NLS-1$
            log.warn("Unsupported confirmation dialog result: " + result);
            return ConfirmResult.NO;
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 12 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project sling by apache.

the class JcrNewNodeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelection(event);
    JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
    if (node == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShell(event);
    if (!node.canCreateChild()) {
        MessageDialog.openInformation(shell, "Cannot create node", "Node is not covered by the workspace filter as defined in filter.xml");
        return null;
    }
    Repository repository = ServerUtil.getDefaultRepository(node.getProject());
    NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
    if (ntManager == null) {
        if (!doNotAskAgain) {
            MessageDialog dialog = new MessageDialog(null, "Unable to validate node type", null, "Unable to validate node types since project " + node.getProject().getName() + " is not associated with a server or the server is not started.", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "Continue (do not ask again)", "Continue" }, 1) {

                @Override
                protected void configureShell(Shell shell) {
                    super.configureShell(shell);
                    setShellStyle(getShellStyle() | SWT.SHEET);
                }
            };
            int choice = dialog.open();
            if (choice <= 0) {
                return null;
            }
            if (choice == 1) {
                doNotAskAgain = true;
            }
        }
    }
    final NodeType nodeType = node.getNodeType();
    if (nodeType != null && nodeType.getName() != null && nodeType.getName().equals("nt:file")) {
        MessageDialog.openInformation(shell, "Cannot create node", "Node of type nt:file cannot have children");
        return null;
    }
    try {
        final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
        if (nnd.open() == IStatus.OK) {
            node.createChild(nnd.getValue(), nnd.getChosenNodeType());
            return null;
        }
    } catch (RepositoryException e1) {
        Activator.getDefault().getPluginLogger().warn("Could not open NewNodeDialog due to " + e1, e1);
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Repository(org.apache.sling.ide.transport.Repository) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) NodeType(javax.jcr.nodetype.NodeType) ISelection(org.eclipse.jface.viewers.ISelection) NodeTypeRegistry(org.apache.sling.ide.transport.NodeTypeRegistry) RepositoryException(org.apache.sling.ide.transport.RepositoryException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 13 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project eclipse.platform.text by eclipse.

the class ConvertLineDelimitersAction method filterUnacceptableFiles.

/**
 * Filters the unacceptable files.
 *
 * @param files the files to filter
 * @return an array of files
 * @since 3.2
 */
private IFile[] filterUnacceptableFiles(IFile[] files) {
    boolean askForBinary = true;
    Set<IFile> filtered = new HashSet<>();
    for (int i = 0; i < files.length; i++) {
        IFile file = files[i];
        if (isAcceptableLocation(file.getFullPath())) {
            filtered.add(file);
        } else if (askForBinary) {
            int result = new MessageDialog(getShell(), getDialogTitle(), null, TextEditorMessages.ConvertLineDelimitersAction_nontext_selection, MessageDialog.WARNING, new String[] { TextEditorMessages.ConvertLineDelimitersAction_convert_all, TextEditorMessages.ConvertLineDelimitersAction_convert_text, IDialogConstants.CANCEL_LABEL }, 1).open();
            if (result == 0) {
                fStrictCheckIfTextLocation = false;
                filtered.add(file);
            } else if (result == 1) {
                askForBinary = false;
            } else {
                return null;
            }
        }
    }
    return filtered.toArray(new IFile[filtered.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) HashSet(java.util.HashSet)

Example 14 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method handleEditorInputChanged.

/**
 * Handles an external change of the editor's input element. Subclasses may
 * extend.
 */
protected void handleEditorInputChanged() {
    String title;
    String msg;
    Shell shell = getSite().getShell();
    final IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=15066
        close(false);
        return;
    }
    final IEditorInput input = getEditorInput();
    final String inputName = input.getToolTipText();
    if (provider.isDeleted(input)) {
        if (isSaveAsAllowed()) {
            title = EditorMessages.Editor_error_activated_deleted_save_title;
            msg = NLSUtility.format(EditorMessages.Editor_error_activated_deleted_save_message, inputName);
            String[] buttons = { EditorMessages.Editor_error_activated_deleted_save_button_save, EditorMessages.Editor_error_activated_deleted_save_button_close };
            MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);
            if (dialog.open() == 0) {
                IProgressMonitor pm = getProgressMonitor();
                try {
                    performSaveAs(pm);
                    if (pm.isCanceled())
                        handleEditorInputChanged();
                } finally {
                    pm.done();
                }
            } else {
                close(false);
            }
        } else {
            title = EditorMessages.Editor_error_activated_deleted_close_title;
            msg = NLSUtility.format(EditorMessages.Editor_error_activated_deleted_close_message, inputName);
            if (MessageDialog.openConfirm(shell, title, msg))
                close(false);
        }
    } else if (fHasBeenActivated) {
        title = EditorMessages.Editor_error_activated_outofsync_title;
        msg = NLSUtility.format(EditorMessages.Editor_error_activated_outofsync_message, inputName);
        if (MessageDialog.openQuestion(shell, title, msg)) {
            try {
                if (provider instanceof IDocumentProviderExtension) {
                    IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
                    extension.synchronize(input);
                } else {
                    doSetInput(input);
                }
            } catch (CoreException x) {
                IStatus status = x.getStatus();
                if (status == null || status.getSeverity() != IStatus.CANCEL) {
                    title = EditorMessages.Editor_error_refresh_outofsync_title;
                    msg = NLSUtility.format(EditorMessages.Editor_error_refresh_outofsync_message, inputName);
                    ErrorDialog.openError(shell, title, msg, x.getStatus());
                }
            }
        } else if (!isDirty()) {
            // Trigger dummy change to dirty the editor, for details see https://bugs.eclipse.org/344101 .
            try {
                IDocument document = provider.getDocument(input);
                if (document != null)
                    // $NON-NLS-1$
                    document.replace(0, 0, "");
            } catch (BadLocationException e) {
            // Ignore as this can't happen
            }
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 15 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project eclipse.platform.text by eclipse.

the class SpellingConfigurationBlock method createProviderViewer.

private ComboViewer createProviderViewer() {
    /* list viewer */
    final ComboViewer viewer = new ComboViewer(fProviderCombo);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer v, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fProviderDescriptors.values().toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            return ((SpellingEngineDescriptor) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty())
                return;
            if (fCurrentBlock != null && fStatusMonitor.getStatus() != null && fStatusMonitor.getStatus().matches(IStatus.ERROR))
                if (isPerformRevert()) {
                    ISafeRunnable runnable = new ISafeRunnable() {

                        @Override
                        public void run() throws Exception {
                            fCurrentBlock.performRevert();
                        }

                        @Override
                        public void handleException(Throwable x) {
                        }
                    };
                    SafeRunner.run(runnable);
                } else {
                    revertSelection();
                    return;
                }
            fStore.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, ((SpellingEngineDescriptor) sel.getFirstElement()).getId());
            updateListDependencies();
        }

        private boolean isPerformRevert() {
            Shell shell = viewer.getControl().getShell();
            MessageDialog dialog = new MessageDialog(shell, TextEditorMessages.SpellingConfigurationBlock_error_title, null, TextEditorMessages.SpellingConfigurationBlock_error_message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
            return dialog.open() == 0;
        }

        private void revertSelection() {
            try {
                viewer.removeSelectionChangedListener(this);
                SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
                if (desc != null)
                    viewer.setSelection(new StructuredSelection(desc), true);
            } finally {
                viewer.addSelectionChangedListener(this);
            }
        }
    });
    viewer.setInput(fProviderDescriptors);
    viewer.refresh();
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) Shell(org.eclipse.swt.widgets.Shell) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

MessageDialog (org.eclipse.jface.dialogs.MessageDialog)44 Shell (org.eclipse.swt.widgets.Shell)13 CoreException (org.eclipse.core.runtime.CoreException)7 File (java.io.File)5 IPath (org.eclipse.core.runtime.IPath)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IFile (org.eclipse.core.resources.IFile)4 Point (org.eclipse.swt.graphics.Point)4 Composite (org.eclipse.swt.widgets.Composite)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Path (org.eclipse.core.runtime.Path)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IProject (org.eclipse.core.resources.IProject)2