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

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

Introduction

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

Prototype

int WARNING

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

Click Source Link

Document

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

Usage

From source file:org.eclipse.gyrex.admin.ui.internal.widgets.NonBlockingMessageDialogs.java

License:Open Source License

public static void openWarning(final Shell parent, final String title, final String message,
        final DialogCallback callback) {
    open(MessageDialog.WARNING, parent, title, message, callback);
}

From source file:org.eclipse.ice.materials.ui.MaterialsDatabaseMasterDetailsBlock.java

License:Open Source License

@Override
protected void createMasterPart(IManagedForm managedForm, Composite parent) {

    // Put in an overall section to hold the master block. It is used to
    // notify the workbench of selection events from the try and to look
    // nice./*from  ww w  .  ja va2 s.  co  m*/
    mForm = managedForm;
    FormToolkit toolkit = mForm.getToolkit();
    Section section = toolkit.createSection(parent,
            ExpandableComposite.TITLE_BAR | Section.DESCRIPTION | ExpandableComposite.EXPANDED);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    section.setLayoutData(gridData);
    section.setLayout(new GridLayout(1, true));
    section.setText("Materials Tree");
    section.setDescription("Select a material to edit");

    // Create the area in which the block will be rendered - the
    // "section client"
    Composite sectionClient = toolkit.createComposite(section);
    // Configure the layout to be greedy.
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 2;
    layout.marginHeight = 2;
    // Set the layout and the layout data
    sectionClient.setLayout(layout);
    sectionClient.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Finally tell the section about its client
    section.setClient(sectionClient);

    // Create the SectionPart that holds the section and is registered with
    // the managed form to publish events.
    final SectionPart sectionPart = new SectionPart(section);
    mForm.addPart(sectionPart);

    // Create a composite to hold the tree viewer and the filter text
    Composite treeComp = new Composite(sectionClient, SWT.NONE);
    treeComp.setLayout(new GridLayout(1, false));
    treeComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // Add filter to the Dialog to filter the table results
    final Text filter = new Text(treeComp, SWT.BORDER | SWT.SEARCH);
    filter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

    // Create the tree viewer that shows the contents of the database
    treeViewer = new TreeViewer(treeComp);
    treeViewer.setContentProvider(new MaterialsDatabaseContentProvider());
    treeViewer.setLabelProvider(new MaterialsDatabaseLabelProvider());

    // Create a sorted final list from the database for pulling the database
    // information
    materials = new ArrayList<Material>();
    materials.addAll(materialsDatabase.getMaterials());

    // Sorts the list according to the material compareTo operator
    Collections.sort(materials);

    // Create a copy of the master list for the table to display.
    ArrayList<Object> editableCopy = new ArrayList<Object>();
    for (int i = 0; i < materials.size(); i++) {
        editableCopy.add(materials.get(i));
    }

    // Set the treeviewer input
    treeViewer.setInput(editableCopy);

    // Add a modify listener to filter the table as the user types in the
    // filter.
    filter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            List<Material> listFromTree = (List<Material>) treeViewer.getInput();
            // Get the filter text
            String filterText = filter.getText().toLowerCase();

            // Checks to see if this is a search for a specific
            // isotope or a element (in which case all isotopes should be
            // shown through the filter).
            boolean useElementName = !((filterText.length() > 0) && (Character.isDigit(filterText.charAt(0))));

            // Iterate over the list and pick the items to keep from the
            // filter text.
            int numRemoved = 0;
            for (int i = 0; i < materials.size(); i++) {

                Material mat = materials.get(i);

                String matName = "";
                if (useElementName) {
                    matName = mat.getElementalName();
                } else {
                    matName = mat.getName();
                }
                // Finally, if the material fits the filter, make sure it is
                // in the list. Otherwise, take it out of the list.
                if (matName.toLowerCase().startsWith(filterText)) {
                    // make sure material is in list
                    if (!listFromTree.contains(mat)) {
                        listFromTree.add(i - numRemoved, mat);
                    }

                } else {

                    // remove materials that do not fit the search criteria.
                    if (listFromTree.contains(mat)) {
                        listFromTree.remove(mat);
                    }
                    numRemoved++;
                }
            }
            // Refresh the tree viewer so that it is repainted
            treeViewer.refresh();
        }
    });

    // Lay out the list
    treeViewer.getTree().setLayout(new GridLayout(1, true));

    // Sets the gridData to grab the available space, but to have only the
    // treeview have the scrolling. This allows for the master tree to
    // scroll without moving the details page out of the viewport.
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    data.widthHint = sectionClient.getClientArea().width;
    data.heightHint = sectionClient.getClientArea().height;
    treeViewer.getTree().setLayoutData(data);

    // Add a listener to notify the managed form when a selection is made so
    // that its details can be presented.
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            mForm.fireSelectionChanged(sectionPart, event.getSelection());
        }
    });

    // Add a composite for holding the Add and Delete buttons for adding
    // or removing materials
    Composite buttonComposite = new Composite(sectionClient, SWT.NONE);
    buttonComposite.setLayout(new GridLayout(1, false));
    buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true, 1, 1));

    // Create the Add button
    Button addMaterialButton = new Button(buttonComposite, SWT.PUSH);
    addMaterialButton.setText("Add");

    // Add a listener to the add button to open the Add Material Wizard
    addMaterialButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // Create a wizard dialog to hold the AddMaterialWizard that
            // will be
            // used to create new materials.
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            AddMaterialWizard addMaterialWizard = new AddMaterialWizard(window, materialsDatabase);
            addMaterialWizard.setWindowTitle("Create a new material");
            WizardDialog addMaterialDialog = new WizardDialog(window.getShell(), addMaterialWizard);

            // Get the new material to add
            if (addMaterialDialog.open() == Window.OK) {
                Material newMaterial = addMaterialWizard.getMaterial();

                //materials.getReadWriteLock().writeLock().lock();
                try {
                    materials.add(newMaterial);
                    Collections.sort(materials);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    //materials.getReadWriteLock().writeLock().unlock();
                }

                // Add to database
                materialsDatabase.addMaterial(newMaterial);

                // Add to tree's list
                ArrayList<Material> listFromTree = (ArrayList<Material>) treeViewer.getInput();
                listFromTree.add(newMaterial);
                Collections.sort(listFromTree);
                treeViewer.refresh();
            }

        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // Nothing TODO
        }
    });

    // Create the Delete button
    Button deleteMaterialButton = new Button(buttonComposite, SWT.PUSH);
    deleteMaterialButton.setText("Delete");
    // Create a listener that will throw up a warning message before
    // performing the actual deletion from the database.The message is just
    // a simple JFace message dialog that is opened when either button
    // is pressed.
    String title = "Confirm Deletion";
    String msg = "Are you sure you want to delete this material(s)?";
    String[] labels = { "OK", "Cancel" };
    final MessageDialog deletionDialog = new MessageDialog(parent.getShell(), title, null, msg,
            MessageDialog.WARNING, labels, 0);
    SelectionListener deletionListener = new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = deletionDialog.open();
            // If the user presses OK
            if (index == 0) {
                // Get the currently selected materials
                IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
                Iterator it = selection.iterator();

                // Get the model from the treeViewer
                List<Material> listFromTree = (List<Material>) treeViewer.getInput();

                // Remove each selected material
                while (it.hasNext()) {
                    Material toDelete = (Material) it.next();
                    // Remove the material from the user's database
                    materialsDatabase.deleteMaterial(toDelete);

                    //materials.getReadWriteLock().writeLock().lock();
                    try {
                        // Remove from the master materials list
                        materials.remove(toDelete);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        //materials.getReadWriteLock().writeLock().unlock();
                    }
                    // Remove the material from the tree viewer
                    listFromTree.remove(toDelete);
                }

                // Update the treeViwer so that it repaints and shows the
                // changes on screen.
                treeViewer.refresh();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // nothing TODO
        }
    };
    deleteMaterialButton.addSelectionListener(deletionListener);

    // Create the Restore Defaults button
    Button restoreMaterialButton = new Button(buttonComposite, SWT.PUSH);
    restoreMaterialButton.setText("Reset");
    restoreMaterialButton.setToolTipText("Restore the database to " + "its initial state.");
    // Create a listener that will throw up a warning message before
    // performing the actual deletion from the database.The message is just
    // a simple JFace message dialog that is opened when either button
    // is pressed.
    title = "Confirm Restoration to Initial State";
    msg = "Are you sure you want restore the " + "database to its initial configuration? "
            + "This will erase ALL of your changes " + "and updates, and it cannot be undone.";
    final MessageDialog restoreDialog = new MessageDialog(parent.getShell(), title, null, msg,
            MessageDialog.WARNING, labels, 0);
    SelectionListener restoreListener = new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = restoreDialog.open();
            if (index == 0) {
                materialsDatabase.restoreDefaults();
                // Create a sorted final list from the database for pulling
                // the database information
                List newList = materialsDatabase.getMaterials();
                //materials.getReadWriteLock().writeLock().lock();
                try {
                    materials.clear();
                    materials.addAll(newList);
                    // Sorts the list according to the material compareTo
                    // operator
                    Collections.sort(materials);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    //materials.getReadWriteLock().writeLock().unlock();
                }

                // Get the model from the treeViewer
                List listFromTree = (List<Object>) treeViewer.getInput();
                // Refresh the list from the reset materials database
                listFromTree.clear();
                for (int i = 0; i < materials.size(); i++) {
                    listFromTree.add(materials.get(i));
                }

                // Update the treeViwer so that it repaints and shows the
                // changes on screen.
                treeViewer.refresh();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            int index = restoreDialog.open();
            // Do the restore - NOT YET IMPLEMENTED!
        }
    };
    restoreMaterialButton.addSelectionListener(restoreListener);

    return;
}

From source file:org.eclipse.jdt.ui.actions.SortMembersAction.java

License:Open Source License

private void run(Shell shell, ICompilationUnit cu, IEditorPart editor, boolean isNotSortFields) {
    if (containsRelevantMarkers(editor)) {
        int returnCode = OptionalMessageDialog.open(ID_OPTIONAL_DIALOG, getShell(), getDialogTitle(), null,
                ActionMessages.SortMembersAction_containsmarkers, MessageDialog.WARNING,
                new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
        if (returnCode != OptionalMessageDialog.NOT_SHOWN && returnCode != Window.OK)
            return;
    }/*  w  w w .j  a  va 2 s.co  m*/

    SortMembersOperation op = new SortMembersOperation(cu, null, isNotSortFields);
    try {
        BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext();
        PlatformUI.getWorkbench().getProgressService().runInUI(context,
                new WorkbenchRunnableAdapter(op, op.getScheduleRule()), op.getScheduleRule());
    } catch (InvocationTargetException e) {
        ExceptionHandler.handle(e, shell, getDialogTitle(), null);
    } catch (InterruptedException e) {
        // Do nothing. Operation has been canceled by user.
    }
}

From source file:org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveJPAEntityFeature.java

License:Open Source License

@Override
public void execute(IContext ctx) {
    if (!IRemoveContext.class.isInstance(ctx))
        return;//ww  w . ja v a 2  s.co  m
    final IRemoveContext context = (IRemoveContext) ctx;
    PictogramElement pe = context.getPictogramElement();
    Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe);
    if (!PersistentType.class.isInstance(bo))
        return;
    PersistentType jpt = (PersistentType) bo;
    if (JPAEditorUtil.isEntityOpenElsewhere(jpt, true)) {
        String shortEntName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt));
        String message = NLS.bind(JPAEditorMessages.RemoveJPAEntityFeature_discardWarningMsg, shortEntName);
        MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                JPAEditorMessages.JPASolver_closeEditors, null, message, MessageDialog.WARNING,
                new String[] { JPAEditorMessages.BTN_OK, JPAEditorMessages.BTN_CANCEL }, 0) {
            @Override
            protected int getShellStyle() {
                return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | getDefaultOrientation();
            }
        };
        if (dialog.open() != 0)
            return;
    }
    TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe);
    ted.getCommandStack().execute(new RecordingCommand(ted) {
        @Override
        protected void doExecute() {
            removeEntityFromDiagram(context);
        }
    });

}

From source file:org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RestoreEntityFeature.java

License:Open Source License

public void execute(ICustomContext context) {
    PersistentType jpt = (PersistentType) getFeatureProvider()
            .getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
    if (JPAEditorUtil.isEntityOpenElsewhere(jpt, true)) {
        String shortEntName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt));
        String message = NLS.bind(JPAEditorMessages.JPASolver_closeWarningMsg, shortEntName);
        MessageDialog dialog = new MessageDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                JPAEditorMessages.JPASolver_closeEditors, null, message, MessageDialog.WARNING,
                new String[] { JPAEditorMessages.BTN_OK }, 0) {
            @Override//  w w w .  j  a  v a 2  s  .c  om
            protected int getShellStyle() {
                return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | getDefaultOrientation();
            }
        };
        dialog.open();
        return;
    }
    JpaArtifactFactory.instance().restoreEntityClass(jpt, getFeatureProvider());
}

From source file:org.eclipse.jst.j2ee.internal.dialogs.DependencyConflictResolveDialog.java

License:Open Source License

public DependencyConflictResolveDialog(Shell parentShell, int dlgType) {

    super(parentShell, J2EEUIMessages.getResourceString(J2EEUIMessages.DEPENDENCY_CONFLICT_TITLE), null,
            J2EEUIMessages.getResourceString((dlgType == DLG_TYPE_1) ? J2EEUIMessages.DEPENDENCY_CONFLICT_MSG_1
                    : J2EEUIMessages.DEPENDENCY_CONFLICT_MSG_2)

            , MessageDialog.WARNING,

            new String[] { J2EEUIMessages.OK_BUTTON, J2EEUIMessages.CANCEL_BUTTON }, BTN_ID_CANCEL,
            J2EEUIMessages.getResourceString(J2EEUIMessages.DO_NOT_SHOW_WARNING_AGAIN), false);
}

From source file:org.eclipse.linuxtools.dataviewers.dialogs.STDataViewersExportToCSVDialog.java

License:Open Source License

@Override
protected void okPressed() {
    File f = new File(outputFile.getText());
    if (f.exists()) {
        MessageDialog dialog = new MessageDialog(this.getShell(), "Warning: file already exists", null,
                "File \"" + f.getAbsolutePath() + "\" already exists.\n" + "Overwrite it anyway?",
                MessageDialog.WARNING, new String[] { "OK", "Cancel" }, 1);
        if (dialog.open() > 0) {
            return;
        }//from  w  w w.  ja  va2  s.  c o  m
    }

    if (isDirty()) {
        saveExporterSettings();
    }
    super.okPressed();
}

From source file:org.eclipse.lsp4e.ui.LoggingPreferencePage.java

License:Open Source License

@Override
public boolean performOk() {
    if (hasLoggingBeenChanged) {
        applyLoggingEnablment();//from  www. j a  va2s.  c  om
        MessageDialog dialog = new MessageDialog(getShell(), Messages.PreferencesPage_restartWarning_title,
                null, Messages.PreferencesPage_restartWarning_message, MessageDialog.WARNING,
                new String[] { IDialogConstants.NO_LABEL, Messages.PreferencesPage_restartWarning_restart }, 1);
        if (dialog.open() == 1) {
            PlatformUI.getWorkbench().restart();
        }
    }
    return super.performOk();
}

From source file:org.eclipse.m2e.editor.pom.FormUtils.java

License:Open Source License

private static FormHoverProvider.Execute createDefaultPerformer(final ScrolledForm form, final String message,
        final String ttip, final int severity) {
    if (ttip != null && ttip.length() > 0 && message != null) {
        return new FormHoverProvider.Execute() {

            public void run(Point point) {
                int dialogSev = IMessageProvider.ERROR == severity ? MessageDialog.ERROR
                        : MessageDialog.WARNING;
                MavenMessageDialog.openWithSeverity(form.getShell(), Messages.FormUtils_error_info,
                        Messages.FormUtils_pom_error, ttip, dialogSev);
            }// w ww. j a v a2s.  c o  m
        };
    }
    return null;
}

From source file:org.eclipse.mylyn.gerrit.dashboard.ui.views.GerritTableView.java

License:Open Source License

private void displayWarning(final String st) {
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            final MessageDialog dialog = new MessageDialog(null, Messages.GerritTableView_warning, null, st,
                    MessageDialog.WARNING, new String[] { IDialogConstants.CANCEL_LABEL }, 0);
            dialog.open();//from   www  . j  a  v a  2 s .c  om
        }
    });
}