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

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

Introduction

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

Prototype

int INFORMATION

To view the source code for org.eclipse.jface.dialogs MessageDialog INFORMATION.

Click Source Link

Document

Constant for the info image, or a simple dialog with the info image and a single OK button (value 2).

Usage

From source file:org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryWizard.java

License:Open Source License

/**
 * {@inheritDoc}//from w w w  .  ja v a2  s .  c  o  m
 */
public boolean performFinish() {
    if (fHeadlessErrorStatus)
        return true;
    if (fOverviewPage != null)
        fOverviewPage.performFinish();
    final IWizardContainer wizard = getContainer();
    final RefactoringStatus status = new RefactoringStatus();
    final RefactoringDescriptorProxy[] proxies = getRefactoringDescriptors();
    final List list = new ArrayList(proxies.length);
    for (int index = fCurrentRefactoring; index < proxies.length; index++)
        list.add(proxies[index]);
    final RefactoringDescriptorProxy[] descriptors = new RefactoringDescriptorProxy[list.size()];
    list.toArray(descriptors);
    final boolean last = isLastRefactoring();
    if (wizard.getCurrentPage() == fPreviewPage && last) {
        final Refactoring refactoring = fPreviewPage.getRefactoring();
        final Change change = fPreviewPage.getChange();
        if (refactoring != null && change != null) {
            status.merge(performPreviewChange(change, refactoring));
            if (!status.isOK()) {
                final RefactoringStatusEntry entry = status.getEntryWithHighestSeverity();
                if (entry.getSeverity() == RefactoringStatus.INFO
                        && entry.getCode() == RefactoringHistoryWizard.STATUS_CODE_INTERRUPTED)
                    return false;
                fErrorPage.setStatus(status);
                fErrorPage.setNextPageDisabled(true);
                fErrorPage.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error_title);
                fErrorPage.setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error);
                wizard.showPage(fErrorPage);
                return false;
            }
        }
    } else {
        final IPreferenceStore store = RefactoringUIPlugin.getDefault().getPreferenceStore();
        if (!store.getBoolean(PREFERENCE_DO_NOT_WARN_FINISH) && proxies.length > 0) {
            final MessageDialogWithToggle dialog = new MessageDialogWithToggle(getShell(),
                    wizard.getShell().getText(), null,
                    Messages.format(RefactoringUIMessages.RefactoringHistoryWizard_warning_finish,
                            LegacyActionTools.removeMnemonics(IDialogConstants.FINISH_LABEL)),
                    MessageDialog.INFORMATION,
                    new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                    RefactoringUIMessages.RefactoringHistoryWizard_do_not_show_message, false);
            dialog.open();
            store.setValue(PREFERENCE_DO_NOT_WARN_FINISH, dialog.getToggleState());
            if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID)
                return false;
        }
        final PerformRefactoringHistoryOperation operation = new PerformRefactoringHistoryOperation(
                new RefactoringHistoryImplementation(descriptors)) {

            protected RefactoringContext createRefactoringContext(final RefactoringDescriptor descriptor,
                    final RefactoringStatus state, IProgressMonitor monitor) throws CoreException {
                return RefactoringHistoryWizard.this.createRefactoringContext(descriptor, state, monitor);
            }

            protected void refactoringPerformed(final Refactoring refactoring, final IProgressMonitor monitor) {
                SafeRunner.run(new ISafeRunnable() {

                    public void handleException(final Throwable exception) {
                        RefactoringUIPlugin.log(exception);
                    }

                    public final void run() throws Exception {
                        RefactoringHistoryWizard.this.refactoringPerformed(refactoring, monitor);
                    }
                });
            }

            public void run(final IProgressMonitor monitor) throws CoreException {
                try {
                    monitor.beginTask(RefactoringUIMessages.RefactoringHistoryWizard_preparing_refactorings,
                            100);
                    if (!fAboutToPerformFired) {
                        try {
                            status.merge(fireAboutToPerformHistory(new SubProgressMonitor(monitor, 20,
                                    SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
                        } finally {
                            fAboutToPerformFired = true;
                        }
                    }
                    if (!status.isOK()) {
                        final int severity = status.getSeverity();
                        throw new CoreException(
                                new Status(severity != RefactoringStatus.FATAL ? severity : IStatus.ERROR,
                                        RefactoringUIPlugin.getPluginId(), 0, null, null));
                    }
                    super.run(new SubProgressMonitor(monitor, 80, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            wizard.run(false, false,
                    new WorkbenchRunnableAdapter(operation, ResourcesPlugin.getWorkspace().getRoot()));
        } catch (InvocationTargetException exception) {
            RefactoringUIPlugin.log(exception);
            final Throwable throwable = exception.getTargetException();
            if (throwable != null) {
                final String message = throwable.getLocalizedMessage();
                if (message != null && !"".equals(message)) //$NON-NLS-1$
                    status.merge(RefactoringStatus.createFatalErrorStatus(message));
                fErrorPage.setStatus(status);
                fErrorPage.setNextPageDisabled(status.hasFatalError());
                fErrorPage.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error_title);
                fErrorPage.setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error);
                wizard.showPage(fErrorPage);
                return false;
            }
        } catch (InterruptedException exception) {
            // Does not happen
        }
        final RefactoringStatus result = operation.getExecutionStatus();
        if (!result.isOK()) {
            fHeadlessErrorStatus = true;
            fErrorPage.setStatus(result);
            fErrorPage.setNextPageDisabled(true);
            fErrorPage.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_finish_error_title);
            fErrorPage.setDescription(
                    RefactoringUIMessages.RefactoringHistoryPreviewPage_finish_error_description);
            wizard.showPage(fErrorPage);
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.m2e.pr.internal.wizard.ProblemReportingWizard.java

License:Open Source License

public boolean performFinish() {
    final Set<Data> dataSet = new HashSet<Data>();//selectionPage.getDataSet();
    dataSet.addAll(EnumSet.allOf(Data.class));
    dataSet.remove(Data.MAVEN_POM_FILES);
    //    if(locationFile.exists()) {
    //      if(!MessageDialog.openQuestion(getShell(), "File already exists", //
    //          "File " + location + " already exists.\nDo you want to overwrite?")) {
    //        return false;
    //      }//from   w w w.  j av a  2s .c o  m
    //      if(!locationFile.delete()) {
    //        MavenLogger.log("Can't delete file " + location, null);
    //      }
    //    }

    new Job(Messages.ProblemReportingWizard_job_gathering) {
        protected IStatus run(IProgressMonitor monitor) {
            List<File> bundleFiles = null;
            try {
                String tmpPath = ResourcesPlugin.getPlugin().getStateLocation().toOSString();
                File tmpDir = new File(tmpPath);
                bundleFiles = saveData(tmpDir, dataSet, monitor);
                IMavenConfiguration mavenConfiguration = MavenPlugin.getDefault().getMavenConfiguration();
                String username = mavenConfiguration.getJiraUsername();
                String password = mavenConfiguration.getJiraPassword();
                if (username == null || username.trim().equals("")) { //$NON-NLS-1$
                    username = USERNAME;
                    password = PASSWORD;
                }

                IssueSubmitter is = new JiraIssueSubmitter(URL,
                        new DefaultAuthenticationSource(username, password));

                IssueSubmissionRequest r = new IssueSubmissionRequest();
                r.setProjectId(PROJECT);
                r.setSummary(descriptionPage.getProblemSummary());
                r.setDescription(descriptionPage.getProblemDescription());
                r.setReporter(username);
                r.setEnvironment(getEnvironment());

                //
                // Problem Report Bundles
                //
                for (File bundleFile : bundleFiles) {
                    r.addProblemReportBundle(bundleFile);
                }

                //
                // Screen Captures
                //
                if (descriptionPage.getScreenCapture() != null && descriptionPage.getScreenCapture().isFile()) {
                    r.addScreenCapture(descriptionPage.getScreenCapture());
                }

                IssueSubmissionResult res = is.submitIssue(r);

                showHyperlink(Messages.ProblemReportingWizard_link_success, res.getIssueUrl());
            } catch (Exception ex) {
                MavenLogger.log("Failed to generate problem report", ex);
                showError((ex.getMessage() != null) ? ex.getMessage() : ex.toString());
            } finally {
                if (bundleFiles != null) {
                    for (File bundleFile : bundleFiles) {
                        bundleFile.delete();
                    }
                }
            }

            return Status.OK_STATUS;
        }

        private void showError(final String msg) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    MessageDialog.openError(Display.getCurrent().getActiveShell(), //
                            TITLE, msg);
                }
            });
        }

        private void showHyperlink(final String msg, final String url) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    HyperlinkDialog dialog = new HyperlinkDialog(Display.getCurrent().getActiveShell(), TITLE,
                            null, msg, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0,
                            url);
                    dialog.open();
                }
            });
        }
    }.schedule();

    return true;
}

From source file:org.eclipse.mylyn.internal.monitor.usage.CheckForUploadJob.java

License:Open Source License

synchronized void checkForStatisticsUpload() {

    Date currentTime = new Date();
    if (shouldAskForUpload(currentTime)) {

        String ending = getUserPromptDelay() == 1 ? "" : "s"; //$NON-NLS-1$//$NON-NLS-2$
        MessageDialog message = new MessageDialog(Display.getDefault().getActiveShell(),
                Messages.UiUsageMonitorPlugin_Send_Usage_Feedback, null,
                Messages.UiUsageMonitorPlugin_Help_Improve_Eclipse_And_Mylyn, MessageDialog.QUESTION,
                new String[] { Messages.UiUsageMonitorPlugin_Submit_Feedback, NLS
                        .bind(Messages.UiUsageMonitorPlugin_Remind_Me_In_X_Days, getUserPromptDelay(), ending),
                        Messages.UiUsageMonitorPlugin_Dont_Ask_Again, },
                0);/*  ww w.j  a v  a2 s .c o m*/
        int result = message.open();
        if (result == 0) {
            // time must be stored right away into preferences, to prevent
            // other threads
            UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                    .setValue(MonitorPreferenceConstants.PREF_PREVIOUS_TRANSMIT_DATE, currentTime.getTime());

            if (!UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                    .contains(MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED)
                    || !UiUsageMonitorPlugin.getDefault().getPreferenceStore().getBoolean(
                            MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED)) {
                MessageDialog consentMessage = new MessageDialog(Display.getDefault().getActiveShell(),
                        Messages.UiUsageMonitorPlugin_Consent, null,
                        Messages.UiUsageMonitorPlugin_All_Data_Public, MessageDialog.INFORMATION,
                        new String[] { IDialogConstants.OK_LABEL }, 0);
                consentMessage.open();
                UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue(
                        MonitorPreferenceConstants.PREF_MONITORING_MYLYN_ECLIPSE_ORG_CONSENT_VIEWED, true);
            }

            UsageSubmissionWizard wizard = new UsageSubmissionWizard();
            wizard.init(PlatformUI.getWorkbench(), null);
            // Instantiates the wizard container with the wizard and
            // opens it
            WizardDialog dialog = new UsageSubmissionWizardDialog(Display.getDefault().getActiveShell(),
                    wizard);
            dialog.create();
            dialog.open();

            /*
             * the UI usage report is loaded asynchronously so there's no
             * synchronous way to know if it failed if (wizard.failed()) {
             * lastTransmit.setTime(currentTime.getTime() + DELAY_ON_FAILURE -
             * studyParameters.getTransmitPromptPeriod());
             * plugin.getPreferenceStore().setValue(MylynMonitorPreferenceConstants.PREF_PREVIOUS_TRANSMIT_DATE,
             * currentTime.getTime()); }
             */

        } else {
            if (result == 1) {
                UiUsageMonitorPlugin.getDefault().userCancelSubmitFeedback(currentTime, true);
            } else {
                UiUsageMonitorPlugin.getDefault().getPreferenceStore()
                        .setValue(MonitorPreferenceConstants.PREF_MONITORING_ENABLE_SUBMISSION, false);
            }
        }
        message.close();
    }
}

From source file:org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractNewRepositoryTaskEditor.java

License:Open Source License

@Override
public void doSave(IProgressMonitor monitor) {
    new MessageDialog(null, "Operation not supported", null,
            "Save of un-submitted new tasks is not currently supported.\nPlease submit all new tasks.",
            MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0).open();
    monitor.setCanceled(true);/*from  w  ww.  java2 s. c  o m*/
    return;
}

From source file:org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal.java

License:Open Source License

private static void displayStatus(Shell shell, final String title, final IStatus status,
        boolean showLinkToErrorLog) {
    // avoid blocking ui when in test mode
    if (CoreUtil.TEST_MODE) {
        StatusHandler.log(status);/*  w  w w  . j  a  va  2  s .c o  m*/
        return;
    }

    if (status instanceof RepositoryStatus && ((RepositoryStatus) status).isHtmlMessage()) {
        WebBrowserDialog.openAcceptAgreement(shell, title, status.getMessage(),
                ((RepositoryStatus) status).getHtmlMessage());
    } else {
        String message = status.getMessage();
        if (message == null || message.trim().length() == 0) {
            message = Messages.TasksUiInternal_An_unknown_error_occurred;
        }
        if (message.length() > 256) {
            message = message.substring(0, 256) + "..."; //$NON-NLS-1$
        }
        if (showLinkToErrorLog) {
            message += "\n\n" + Messages.TasksUiInternal_See_error_log_for_details; //$NON-NLS-1$
        }
        switch (status.getSeverity()) {
        case IStatus.CANCEL:
        case IStatus.INFO:
            createDialog(shell, title, message, MessageDialog.INFORMATION).open();
            break;
        case IStatus.WARNING:
            createDialog(shell, title, message, MessageDialog.WARNING).open();
            break;
        case IStatus.ERROR:
        default:
            createDialog(shell, title, message, MessageDialog.ERROR).open();
            break;
        }
    }
}

From source file:org.eclipse.mylyn.reviews.r4e.report.internal.dialog.ReportGeneration.java

License:Open Source License

/**
 * Method notifying the user the generation of the report is completed, and open the report in the workbench editor
 *///from   ww  w.  j a va 2s  .c o m
private void displayReport() {
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            String[] buttonLabels = { "OK" };
            final MessageDialog dialog = new MessageDialog(null, "Report Generated", null,
                    "The following report has been generated: \n" + getReportName(), MessageDialog.INFORMATION,
                    buttonLabels, 0);
            dialog.open();

            // To open in the workspace file editor
            openFile();
        }
    });
}

From source file:org.eclipse.nebula.snippets.grid.viewer.GridViewerSnippetDisposePerformance.java

License:Open Source License

public GridViewerSnippetDisposePerformance(final Shell shell, boolean createButtons) {
    final GridTableViewer v = new GridTableViewer(new Grid(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL) {
        @Override/* w w w  .  j av a2 s .  c o  m*/
        protected void onKeyDown(Event e) {
            super.onKeyDown(e);
            System.out.println(e.keyCode + " Called");
        }
    });
    v.setLabelProvider(new MyLabelProvider());
    v.setContentProvider(new MyContentProvider());
    v.getGrid().setCellSelectionEnabled(true);

    v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });
    v.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        public Object getValue(Object element, String property) {
            if (element == null)
                return "Element is null";
            return "Column " + property + " => " + element.toString();
        }

        public void modify(Object element, String property, Object value) {

        }

    });

    v.setColumnProperties(new String[] { "1", "2" });

    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
                    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
                            && event.keyCode == SWT.CR);
        }
    };

    GridViewerEditor.create(v, actSupport,
            ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
                    | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);

    for (int i = 0; i < NUM_COLUMNS; i++) {
        createColumn(v, "Column " + i);
    }
    if (createButtons) {
        Composite buttons = new Composite(shell, SWT.NONE);
        buttons.setLayout(new RowLayout());

        final Button remove3 = new Button(buttons, SWT.NONE);
        remove3.setText("remove row with index 3");
        final String restore = "restore grid";
        remove3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                //               button.dispose();
                try {
                    v.getGrid().remove(3);
                } catch (java.lang.IllegalArgumentException ie) {
                    new MessageDialog(shell, "IndexOutOfBound error", null,
                            "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                            new String[] { "Ok" }, 0).open();
                }

                shell.layout();
            }
        });

        final Button add3 = new Button(buttons, SWT.NONE);
        add3.setText("add row with index 3");
        add3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                GridItem gridItem = new GridItem(v.getGrid(), SWT.NONE, 3);
                gridItem.setText(0, "Added in 3");
                shell.layout();
            }
        });
        final Button addColumn1 = new Button(buttons, SWT.NONE);
        addColumn1.setText("add column in 1");
        addColumn1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                new GridColumn(v.getGrid(), SWT.NONE, 1);
                shell.layout();
            }
        });
        final Button removeColumn = new Button(buttons, SWT.NONE);
        removeColumn.setText("remove first column");
        removeColumn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                //               button.dispose();
                try {
                    v.getGrid().getColumn(0).dispose();
                    v.getGrid().redraw();
                    v.getGrid().layout();
                } catch (java.lang.IllegalArgumentException ie) {
                    new MessageDialog(shell, "IndexOutOfBound error", null,
                            "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                            new String[] { "Ok" }, 0).open();
                }

                shell.layout();
            }
        });
        final Button hideColumn = new Button(buttons, SWT.NONE);
        hideColumn.setText("hide first column");
        hideColumn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                try {
                    GridColumn[] columns = v.getGrid().getColumns();
                    for (GridColumn gridColumn : columns) {
                        if (gridColumn.isVisible()) {
                            gridColumn.setVisible(false);
                            break;
                        }
                    }
                } catch (java.lang.IllegalArgumentException ie) {
                    new MessageDialog(shell, "IndexOutOfBound error", null,
                            "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                            new String[] { "Ok" }, 0).open();
                }
                shell.layout();
            }
        });
        final Button manualDeselect = new Button(buttons, SWT.NONE);
        manualDeselect.setText("Manual Deselect");
        manualDeselect.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                Grid grid = v.getGrid();
                Point focus = grid.getFocusCell();
                int[] selected = grid.getSelectionIndices();
                grid.deselect(selected);
                grid.remove(selected);
                while (focus.y >= grid.getItemCount())
                    --focus.y;
                if (focus.y >= 0) {
                    grid.setFocusItem(grid.getItem(focus.y));
                    grid.setFocusColumn(grid.getColumn(focus.x));
                    grid.setCellSelection(focus);
                }
            }
        });
        final Button addColumn = new Button(buttons, SWT.NONE);
        addColumn.setText("add column");
        addColumn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                //               button.dispose();
                try {
                    createColumn(v, "Added");
                } catch (java.lang.IllegalArgumentException ie) {
                    new MessageDialog(shell, "IndexOutOfBound error", null,
                            "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                            new String[] { "Ok" }, 0).open();
                }

                shell.layout();
            }
        });
        final Button changeFont = new Button(buttons, SWT.NONE);
        changeFont.setText("Change Default");
        changeFont.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                v.getGrid().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
                v.getGrid().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
                v.getGrid().setFont(
                        registry.getItalic(Display.getCurrent().getSystemFont().getFontData()[0].getName()));
                shell.layout();
            }
        });
        Button exportGrid = new Button(buttons, SWT.NONE);
        exportGrid.setText("Export Grid");
        exportGrid.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                try {
                    if (v.getGrid().isDisposed())
                        return;
                    FileDialog fileDialog = new FileDialog(shell);
                    fileDialog.setFilterExtensions(new String[] { "*.xml" });
                    String open = fileDialog.open();
                    if (open != null) {
                        open = open.endsWith(".xml") ? open : open + ".xml";
                        FileOutputStream outputStream = new FileOutputStream(new File(open));
                        try {
                            GridUtils.gridToXml(v.getGrid(), outputStream);
                            new MessageDialog(shell, "Success", null, "Exported in " + open,
                                    MessageDialog.INFORMATION, new String[] { "Great!" }, 1).open();
                        } catch (ParserConfigurationException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (TransformerException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } finally {
                            try {
                                outputStream.close();
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                } catch (FileNotFoundException e1) {
                    e1.printStackTrace();
                }
            }
        });
        final Button restoreButton = new Button(buttons, SWT.NONE);
        restoreButton.setText(restore);
        restoreButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                GridColumn[] columns = v.getGrid().getColumns();
                for (GridColumn gridColumn : columns) {
                    gridColumn.dispose();
                }
                for (int i = 0; i < NUM_COLUMNS; i++) {
                    createColumn(v, "Column " + i);
                }
                v.setInput(createModel());
                v.getGrid().setItemCount(10);
                v.getGrid().redraw();
                v.getGrid().layout();
                shell.layout();
            }
        });
        final Button enableDisableKeyListenerButton = new Button(buttons, SWT.NONE);
        enableDisableKeyListenerButton.setText("Disable default key listener");
        enableDisableKeyListenerButton.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (enable) {
                    v.getGrid().disableDefaultKeyListener();
                    enable = false;
                    enableDisableKeyListenerButton.setText("Enable default key listener");
                } else {
                    v.getGrid().enableDefaultKeyListener();
                    enable = true;
                    enableDisableKeyListenerButton.setText("Disable default key listener");
                }
            }
        });
        Button gcButton = new Button(buttons, SWT.NONE);
        gcButton.setText("gc");
        gcButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                System.gc();
            }
        });

    }
    MyModel[] model = createModel();
    v.setInput(model);
    v.getGrid().setLinesVisible(true);
    v.getGrid().setHeaderVisible(true);
}

From source file:org.eclipse.nebula.snippets.grid.viewer.GridViewerSnippetDisposeTreeTest.java

License:Open Source License

public GridViewerSnippetDisposeTreeTest(final Shell shell) {
    final GridTreeViewer v = new GridTreeViewer(shell);

    Composite buttons = new Composite(shell, SWT.NONE);
    buttons.setLayout(new RowLayout());
    final Button remove3 = new Button(buttons, SWT.NONE);
    remove3.setText("remove row with index 3");
    final String restore = "restore grid";
    remove3.addMouseListener(new MouseAdapter() {
        @Override//from   ww  w.  j  a v  a2  s  .  co m
        public void mouseDown(MouseEvent e) {
            //               button.dispose();
            try {
                v.getGrid().remove(3);
            } catch (java.lang.IllegalArgumentException ie) {
                new MessageDialog(shell, "IndexOutOfBound error", null,
                        "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                        new String[] { "Ok" }, 0).open();
            }

            shell.layout();
        }
    });
    final Button add3 = new Button(buttons, SWT.NONE);
    add3.setText("add row with index 3");
    add3.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            GridItem gridItem = new GridItem(v.getGrid(), SWT.NONE, 3);
            gridItem.setText(0, "Added in 3");
            shell.layout();
        }
    });
    final Button addColumn1 = new Button(buttons, SWT.NONE);
    addColumn1.setText("add column in 1");
    addColumn1.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            new GridColumn(v.getGrid(), SWT.NONE, 1);
            shell.layout();
        }
    });
    final Button removeColumn = new Button(buttons, SWT.NONE);
    removeColumn.setText("remove first column");
    removeColumn.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            //               button.dispose();
            try {
                v.getGrid().getColumn(0).dispose();
                v.getGrid().redraw();
                v.getGrid().layout();
            } catch (java.lang.IllegalArgumentException ie) {
                new MessageDialog(shell, "IndexOutOfBound error", null,
                        "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                        new String[] { "Ok" }, 0).open();
            }

            shell.layout();
        }
    });
    final Button addColumn = new Button(buttons, SWT.NONE);
    addColumn.setText("add column");
    addColumn.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            //               button.dispose();
            try {
                createColumn(v, "Added");
            } catch (java.lang.IllegalArgumentException ie) {
                new MessageDialog(shell, "IndexOutOfBound error", null,
                        "Restore the grid with button \"" + restore + "\"", MessageDialog.WARNING,
                        new String[] { "Ok" }, 0).open();
            }

            shell.layout();
        }
    });
    Button exportGrid = new Button(buttons, SWT.NONE);
    exportGrid.setText("Export Grid");
    exportGrid.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            try {
                if (v.getGrid().isDisposed())
                    return;
                FileDialog fileDialog = new FileDialog(shell);
                fileDialog.setFilterExtensions(new String[] { "*.xml" });
                String open = fileDialog.open();
                if (open != null) {
                    open = open.endsWith(".xml") ? open : open + ".xml";
                    FileOutputStream outputStream = new FileOutputStream(new File(open));
                    try {
                        GridUtils.gridToXml(v.getGrid(), outputStream);
                        new MessageDialog(shell, "Success", null, "Exported in " + open,
                                MessageDialog.INFORMATION, new String[] { "Great!" }, 1).open();
                    } catch (ParserConfigurationException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (TransformerException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } finally {
                        try {
                            outputStream.close();
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                }
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            }
        }
    });
    final Button changeFont = new Button(buttons, SWT.NONE);
    changeFont.setText("Change Default");
    changeFont.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            v.getGrid().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
            v.getGrid().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
            v.getGrid().setFont(
                    registry.getItalic(Display.getCurrent().getSystemFont().getFontData()[0].getName()));
            shell.layout();
        }
    });
    final Button restoreButton = new Button(buttons, SWT.NONE);
    restoreButton.setText(restore);
    restoreButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            GridColumn[] columns = v.getGrid().getColumns();
            for (GridColumn gridColumn : columns) {
                gridColumn.dispose();
            }
            revertGrid(v);
            shell.layout();
        }
    });
    revertGrid(v);
}

From source file:org.eclipse.net4j.util.ui.security.InteractiveCredentialsProvider.java

License:Open Source License

/**
 * @since 3.4/*from  www .jav a2s  . c  o  m*/
 */
public IPasswordCredentialsUpdate getCredentialsUpdate(final String realm, final String userID,
        final CredentialsUpdateOperation operation) {
    final IPasswordCredentialsUpdate[] update = { null };
    final Display display = UIUtil.getDisplay();
    display.syncExec(new Runnable() {
        public void run() {
            Shell shell = UIUtil.getShell();

            if (operation == CredentialsUpdateOperation.CHANGE_PASSWORD) {
                CredentialsUpdateDialog dialog = new CredentialsUpdateDialog(shell, realm, userID);
                if (dialog.open() == Window.OK) {
                    update[0] = dialog.getCredentials();
                }
            } else {
                CredentialsResetDialog dialog = new CredentialsResetDialog(shell, realm, userID);
                if (dialog.open() == Window.OK) {
                    update[0] = dialog.getCredentials();
                    final String newPassword = new String(update[0].getNewPassword());

                    MessageDialog msg = new MessageDialog(shell,
                            Messages.getString("InteractiveCredentialsProvider.0"), null, //$NON-NLS-1$
                            MessageFormat.format(Messages.getString("InteractiveCredentialsProvider.1"), //$NON-NLS-1$
                                    userID, newPassword),
                            MessageDialog.INFORMATION,
                            new String[] { Messages.getString("InteractiveCredentialsProvider.2"), //$NON-NLS-1$
                                    IDialogConstants.OK_LABEL },
                            0) {

                        @Override
                        protected void buttonPressed(int buttonId) {
                            if (buttonId == 0) {
                                copyToClipboard();
                                // Don't close the dialog
                            } else {
                                // Close the dialog in the usual way
                                super.buttonPressed(IDialogConstants.OK_ID);
                            }
                        }

                        private void copyToClipboard() {
                            Clipboard clipboard = new Clipboard(getShell().getDisplay());

                            try {
                                clipboard.setContents(new Object[] { newPassword },
                                        new Transfer[] { TextTransfer.getInstance() });
                            } finally {
                                clipboard.dispose();
                            }
                        }
                    };

                    msg.open();
                }
            }
        }
    });

    return update[0];
}

From source file:org.eclipse.oomph.setup.ui.wizards.VariablePage.java

License:Open Source License

private void validate() {
    try {/*w  w  w .j a v a  2 s.  c o  m*/
        performer = null;
        incompletePerformers.clear();
        allPromptedPerfomers.clear();

        setButtonState(IDialogConstants.NEXT_ID, false);

        performerCreationJob = new PerformerCreationJob(SETUP_TASK_ANALYSIS_TITLE) {
            @Override
            protected SetupTaskPerformer createPerformer() throws Exception {
                return VariablePage.this.createPerformer(VariablePage.this, fullPrompt);
            }

            @Override
            protected Dialog createDialog() {
                return createDialog(getShell(), SETUP_TASK_ANALYSIS_TITLE, null,
                        "Analyzing the needed setup tasks has taken more than "
                                + (System.currentTimeMillis() - getStart()) / 1000
                                + " seconds.  The Next button will be disabled, though animated, until it completes.  You may continue to modify the values of the variables.",
                        MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
            }

            @Override
            protected void handleDialogResult(int result) {
                if (result == 0) {
                    setDelay(Integer.MAX_VALUE);
                } else {
                    setDelay(2 * getDelay());
                }
            }
        };

        if (delay != 0) {
            performerCreationJob.setDelay(delay);
        }

        performerCreationJob.create();
        delay = performerCreationJob.getDelay();

        Throwable throwable = performerCreationJob.getThrowable();
        if (throwable != null) {
            if (throwable instanceof OperationCanceledException) {
                performerCreationJob = null;
                return;
            }

            throw throwable;
        }

        performer = performerCreationJob.getPerformer();

        UIUtil.asyncExec(getControl(), new Runnable() {
            public void run() {
                performerCreationJob = null;
                if (updateFields()) {
                    validate();
                }
            }
        });

        if (performer == null) {
            setPageComplete(false);
        } else {
            setPageComplete(true);

            if (!prompted) {
                prompted = true;
                gotoNextPage();
            }
        }
    } catch (Throwable t) {
        performerCreationJob = null;
        SetupUIPlugin.INSTANCE.log(t);
        ErrorDialog.open(t);
    }
}