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 int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:net.sf.eclipsensis.editor.NSISEditor.java

License:Open Source License

@Override
protected void installTextDragAndDrop(ISourceViewer viewer) {
    if (mTextDragAndDropEnabled || viewer == null) {
        return;/*from   w w w . j  a  v  a  2 s  .  c  o m*/
    }

    if (mTextDragAndDropInstalled) {
        mTextDragAndDropEnabled = true;
        return;
    }

    final IDragAndDropService dndService = (IDragAndDropService) getSite()
            .getService(IDragAndDropService.class);
    if (dndService == null) {
        return;
    }

    mTextDragAndDropEnabled = true;

    final StyledText st = viewer.getTextWidget();

    // Install drag source
    final ISelectionProvider selectionProvider = viewer.getSelectionProvider();
    final DragSource source = new DragSource(st, DND.DROP_COPY | DND.DROP_MOVE);
    source.setTransfer(new Transfer[] { TextTransfer.getInstance() });
    source.addDragListener(new DragSourceAdapter() {
        String mSelectedText;
        Point mSelection;

        @Override
        public void dragStart(DragSourceEvent event) {
            mTextDragAndDropToken = null;

            if (!mTextDragAndDropEnabled) {
                event.doit = false;
                event.image = null;
                return;
            }

            try {
                mSelection = st.getSelection();
                int offset = st.getOffsetAtLocation(new Point(event.x, event.y));
                Point p = st.getLocationAtOffset(offset);
                if (p.x > event.x) {
                    offset--;
                }
                event.doit = offset > mSelection.x && offset < mSelection.y;

                ISelection selection = selectionProvider.getSelection();
                if (selection instanceof ITextSelection) {
                    mSelectedText = ((ITextSelection) selection).getText();
                } else {
                    mSelectedText = st.getSelectionText();
                }
            } catch (IllegalArgumentException ex) {
                event.doit = false;
            }
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = mSelectedText;
            mTextDragAndDropToken = this; // Can be any non-null object
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            try {
                if (event.detail == DND.DROP_MOVE && validateEditorInputState()) {
                    Point newSelection = st.getSelection();
                    int length = mSelection.y - mSelection.x;
                    int delta = 0;
                    if (newSelection.x < mSelection.x) {
                        delta = length;
                    }
                    st.replaceTextRange(mSelection.x + delta, length, ""); //$NON-NLS-1$

                    if (mTextDragAndDropToken == null) {
                        // Move in same editor - end compound change
                        IRewriteTarget target = (IRewriteTarget) getAdapter(IRewriteTarget.class);
                        if (target != null) {
                            target.endCompoundChange();
                        }
                    }

                }
            } finally {
                mTextDragAndDropToken = null;
            }
        }
    });

    // Install drag target
    DropTargetListener dropTargetListener = new DropTargetAdapter() {
        private Point mSelection;

        @Override
        public void dragEnter(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                //Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_COPY;
                }
            } else {
                mTextDragAndDropToken = null;
                mSelection = st.getSelection();

                if (!mTextDragAndDropEnabled) {
                    event.detail = DND.DROP_NONE;
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_MOVE;
                }
            }
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_COPY;
                }
            } else {
                if (!mTextDragAndDropEnabled) {
                    event.detail = DND.DROP_NONE;
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                if (event.detail == DND.DROP_DEFAULT) {
                    event.detail = DND.DROP_MOVE;
                }
            }
        }

        @Override
        public void dragOver(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)
                    || FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Don't want default feedback- we will do it ourselves
                event.feedback = DND.FEEDBACK_NONE;
                st.setFocus();
                Point location = st.getDisplay().map(null, st, event.x, event.y);
                location.x = Math.max(0, location.x);
                location.y = Math.max(0, location.y);
                int offset;
                try {
                    offset = st.getOffsetAtLocation(new Point(location.x, location.y));
                } catch (IllegalArgumentException ex) {
                    try {
                        offset = st.getOffsetAtLocation(new Point(0, location.y));
                    } catch (IllegalArgumentException ex2) {
                        offset = st.getCharCount();
                        Point maxLocation = st.getLocationAtOffset(offset);
                        if (location.y >= maxLocation.y) {
                            if (location.x < maxLocation.x) {
                                offset = st.getOffsetAtLocation(new Point(location.x, maxLocation.y));
                            }
                        }
                    }
                }
                IDocument doc = getDocumentProvider().getDocument(getEditorInput());
                offset = getCaretOffsetForInsertCommand(doc, offset);

                st.setCaretOffset(offset);
            } else {
                if (!mTextDragAndDropEnabled) {
                    event.feedback = DND.FEEDBACK_NONE;
                    return;
                }

                event.feedback |= DND.FEEDBACK_SCROLL;
            }
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (NSISCommandTransfer.INSTANCE.isSupportedType(event.currentDataType)) {
                insertCommand((NSISCommand) event.data, false);
            } else if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
                int dropNSISFilesAction = NSISPreferences.getInstance().getPreferenceStore()
                        .getInt(DROP_EXTERNAL_FILES_ACTION);
                switch (dropNSISFilesAction) {
                case DROP_EXTERNAL_FILES_ASK:
                    MessageDialog dialog = new MessageDialog(getSite().getShell(),
                            EclipseNSISPlugin.getResourceString("drop.external.files.ask.title"), //$NON-NLS-1$
                            EclipseNSISPlugin.getShellImage(),
                            EclipseNSISPlugin.getResourceString("drop.external.files.ask.message"), //$NON-NLS-1$
                            MessageDialog.QUESTION,
                            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
                    if (dialog.open() != 0) {
                        break;
                    }
                    //$FALL-THROUGH$
                case DROP_EXTERNAL_FILES_OPEN_IN_EDITORS:
                    openFiles((String[]) event.data);
                    return;
                default:
                    break;
                }
                insertFiles((String[]) event.data);
            } else {
                try {
                    if (!mTextDragAndDropEnabled) {
                        return;
                    }

                    if (mTextDragAndDropToken != null && event.detail == DND.DROP_MOVE) {
                        // Move in same editor
                        int caretOffset = st.getCaretOffset();
                        if (mSelection.x <= caretOffset && caretOffset <= mSelection.y) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }

                        // Start compound change
                        IRewriteTarget target = (IRewriteTarget) getAdapter(IRewriteTarget.class);
                        if (target != null) {
                            target.beginCompoundChange();
                        }
                    }

                    if (!validateEditorInputState()) {
                        event.detail = DND.DROP_NONE;
                        return;
                    }

                    String text = (String) event.data;
                    Point newSelection = st.getSelection();
                    st.insert(text);
                    st.setSelectionRange(newSelection.x, text.length());
                } finally {
                    mTextDragAndDropToken = null;
                }
            }
        }
    };
    dndService.addMergedDropTarget(st, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] {
            NSISCommandTransfer.INSTANCE, FileTransfer.getInstance(), TextTransfer.getInstance() },
            dropTargetListener);

    mTextDragAndDropInstalled = true;
    mTextDragAndDropEnabled = true;
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static boolean openConfirm(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    return dialog.open() == 0;
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static void openError(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.ERROR,
            new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static void openInformation(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.INFORMATION,
            new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static boolean openQuestion(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    return dialog.open() == 0;
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static void openWarning(Shell parent, String title, String message, Image icon) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, MessageDialog.WARNING,
            new String[] { IDialogConstants.OK_LABEL }, 0);
    dialog.open();
}

From source file:net.sf.eclipsensis.util.Common.java

License:Open Source License

public static int openMessageDialog(Shell parent, String title, String message, Image icon, int dialogImageType,
        String[] buttons, int defaultIndex) {
    MessageDialog dialog = new MessageDialog(parent, title, icon, message, dialogImageType, buttons,
            defaultIndex);// w w w . ja v a 2  s  . c  o  m
    return dialog.open();
}

From source file:net.sf.fjep.fatjar.wizard.FJExportWizardConfigPage.java

License:Open Source License

private void showOneJARHelp() {
    MessageDialog dialog = new MessageDialog(getShell(), "One-JAR", null, "One-JAR Help",
            MessageDialog.INFORMATION, new String[] { "OK" }, 0) {

        protected Font font;

        public boolean close() {
            boolean result;
            try {
                font.dispose();/*from   w w  w  .  jav  a2  s.  c  o m*/
            } finally {
                result = super.close();
            }
            return result;
        }

        protected Control createCustomArea(Composite parent) {
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.widthHint = 600;
            gd.heightHint = 300;
            String resource = "one-jar-help.txt";
            StringBuffer help = null;
            try {
                help = readText(this.getClass().getResourceAsStream(resource));
            } catch (IOException iox1) {
                help = new StringBuffer();
                help.append("Unable to locate built-in help for One-JAR at: " + resource + ": " + iox1);
            }
            Text text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            font = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
            FontData fd = font.getFontData()[0];
            // Reduce the font-size. TODO: Should make this configurable in
            // preferences.
            fd.setHeight(fd.getHeight() - 2);
            font = new Font(text.getDisplay(), fd);
            text.setFont(font);
            text.setEditable(false);
            text.setLayoutData(gd);
            text.setText(help.toString());

            Hyperlink href = new Hyperlink(parent, SWT.NONE);
            href.setText("http://one-jar.sourceforge.net");
            href.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
            href.setUnderlined(true);
            href.addHyperlinkListener(new IHyperlinkListener() {

                public void linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                }

                public void linkExited(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                }

                public void linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                    try {
                        SystemBrowserFactory factory = new SystemBrowserFactory();
                        factory.createBrowser().displayURL(e.getLabel());
                    } catch (Exception x) {
                        MessageDialog.openError(e.display.getActiveShell(), "Unable to open " + e.getLabel(),
                                "Unable to open browser: \n" + x.getStackTrace());
                    }
                }

            });
            return text;
        }
    };
    dialog.open();

}

From source file:net.sf.fjep.fatjar.wizard.FJExportWizardConfigPage.java

License:Open Source License

/**
 * Show the One-JAR license in a dialogbox. The first time the user sees
 * this they must accept its terms in order to be able to use One-JAR, under
 * its BSD-style license terms./*w ww .  j  a v  a 2 s  .  c om*/
 * 
 * @return The code from the dialog. 0==Accept, 1==Reject.
 */
private int showOneJARLicense() {
    // Show license.
    String buttons[] = new String[] { "Accept", "Decline" };
    MessageDialog dialog = new MessageDialog(getShell(), "One-JAR License", null,
            "One-JAR is licensed according to the following terms.  Please visit http://one-jar.sourceforge.net for more information.",
            MessageDialog.INFORMATION, buttons, 0) {
        protected Control createCustomArea(Composite parent) {
            // Put the license text in the dialog.
            Text text = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY | SWT.MULTI);
            text.setEditable(false);
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = 200;
            text.setLayoutData(gd);
            // Load the license data as a resource. TODO: Resource this
            // name!
            try {
                JarInputStream jis = new JarInputStream(
                        AguiPlugin.class.getResourceAsStream(AguiPlugin.ONE_JAR_BOOT));
                JarEntry entry = (JarEntry) jis.getNextEntry();
                StringBuffer license = new StringBuffer();
                while (entry != null) {
                    if (entry.getName().equals("doc/one-jar-license.txt")) {
                        license = readText(jis);
                        break;
                    }
                    entry = (JarEntry) jis.getNextEntry();
                }
                text.setText(license.toString());
                return text;
            } catch (Exception x) {
                text.setText("The One-JAR license is available at http://one-jar.sourceforge.net");
            }
            return text;
        }
    };
    return dialog.open();
}

From source file:net.sf.fjep.fatjar.wizards.export.ConfigPage.java

License:Open Source License

private void showOneJARHelp() {
    MessageDialog dialog = new MessageDialog(getShell(), "One-JAR", null, "One-JAR Help",
            MessageDialog.INFORMATION, new String[] { "OK" }, 0) {

        protected Font font;

        public boolean close() {
            boolean result;
            try {
                font.dispose();/*from  www  . j a va 2s. com*/
            } finally {
                result = super.close();
            }
            return result;
        }

        protected Control createCustomArea(Composite parent) {
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.widthHint = 600;
            gd.heightHint = 300;
            String resource = "one-jar-help.txt";
            StringBuffer help = null;
            try {
                help = readText(this.getClass().getResourceAsStream(resource));
            } catch (IOException iox1) {
                help = new StringBuffer();
                help.append("Unable to locate built-in help for One-JAR at: " + resource + ": " + iox1);
            }
            Text text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            font = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
            FontData fd = font.getFontData()[0];
            // Reduce the font-size.  TODO: Should make this configurable in preferences.
            fd.setHeight(fd.getHeight() - 2);
            font = new Font(text.getDisplay(), fd);
            text.setFont(font);
            text.setEditable(false);
            text.setLayoutData(gd);
            text.setText(help.toString());

            Hyperlink href = new Hyperlink(parent, SWT.NONE);
            href.setText("http://one-jar.sourceforge.net");
            href.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
            href.setUnderlined(true);
            href.addHyperlinkListener(new IHyperlinkListener() {

                public void linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                }

                public void linkExited(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                }

                public void linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                    try {
                        SystemBrowserFactory factory = new SystemBrowserFactory();
                        factory.createBrowser().displayURL(e.getLabel());
                    } catch (Exception x) {
                        MessageDialog.openError(e.display.getActiveShell(), "Unable to open " + e.getLabel(),
                                "Unable to open browser: \n" + x.getStackTrace());
                    }
                }

            });
            return text;
        }
    };
    dialog.open();

}