Example usage for org.eclipse.jface.dialogs Dialog DLG_IMG_WARNING

List of usage examples for org.eclipse.jface.dialogs Dialog DLG_IMG_WARNING

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog DLG_IMG_WARNING.

Prototype

String DLG_IMG_WARNING

To view the source code for org.eclipse.jface.dialogs Dialog DLG_IMG_WARNING.

Click Source Link

Document

Image registry key for warning image (value "dialog_warning_image").

Usage

From source file:net.refractions.udig.tools.edit.EditBlackboardUtil.java

License:Open Source License

public static void openDataChangedDialog(final ILayer layer, final Envelope dirtyArea) {
    Display d = Display.getCurrent();/*from  ww  w .  ja v a 2  s  .  c  om*/
    if (d == null)
        d = Display.getDefault();

    Condition condition = blackboardLock.newCondition();
    try {
        blackboardLock.lock();
        if (dialog != null) {
            // we're in the display thread, which means that the viewport is repainting since the dialog has any other input blocked.
            // so just return
            if (Display.getCurrent() != null)
                return;
            // the issue is being resolved we should wait for it to be resolved.
            while (dialog != null) {
                try {
                    condition.await(500, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    return;
                }
            }
            return;
        }
    } finally {
        blackboardLock.unlock();
    }

    PlatformGIS.syncInDisplayThread(d, new Runnable() {
        public void run() {
            try {
                blackboardLock.lock();
                if (dirtyAreas.get(layer) == null)
                    return;

                dialog = new Dialog(Display.getCurrent().getActiveShell()) {
                    private final int UPDATE = 1;
                    private final int CLEAR = 2;
                    private final int IGNORE = 3;

                    public Control createDialogArea(Composite parent) {
                        Composite comp = new Composite(parent, SWT.NONE);
                        comp.setLayout(new GridLayout(2, false));
                        Display display = Display.getCurrent();
                        Label label = new Label(comp, SWT.NONE);
                        label.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
                        label.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
                        label.setImage(Dialog.getImage(Dialog.DLG_IMG_WARNING));

                        label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
                        Text text = new Text(comp, SWT.WRAP | SWT.READ_ONLY);
                        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        text.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
                        text.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
                        text.setText(Messages.EditBlackboardUtil_data_changed);
                        return comp;
                    }

                    public void createButtonsForButtonBar(Composite composite) {
                        createButton(composite, UPDATE, Messages.EditBlackboardUtil_update, false);
                        createButton(composite, CLEAR, Messages.EditBlackboardUtil_clear, true);
                        createButton(composite, IGNORE, Messages.EditBlackboardUtil_ignore, false);
                    }

                    public void buttonPressed(int button) {
                        switch (button) {
                        case UPDATE: {
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_Update_Selection,
                                    Messages.EditBlackboardUtil_update_selection_confirmation);
                            if (ok) {
                                try {
                                    ProgressMonitorDialog d = new ProgressMonitorDialog(this.getParentShell());

                                    blackboardLock.unlock();
                                    d.run(false, false, new IRunnableWithProgress() {
                                        public void run(IProgressMonitor monitor) {
                                            updateFeatures(layer, monitor, dirtyArea);
                                        }
                                    });
                                    okPressed();
                                } catch (Exception e) {
                                    EditPlugin.log("", e); //$NON-NLS-1$
                                }
                            }
                            break;
                        }
                        case CLEAR: {
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_clear_selection,
                                    Messages.EditBlackboardUtil_changes_will_be_lost);
                            if (ok) {
                                blackboardLock.unlock();
                                (getEditBlackBoardFromLayer(layer)).clear();
                                layer.getMap().getBlackboard().put(EditToolHandler.CURRENT_SHAPE, null);
                                ((EditManager) layer.getMap().getEditManager()).setEditFeature(null, null);
                                okPressed();
                            }
                            break;
                        }
                        case IGNORE:
                            boolean ok = MessageDialog.openConfirm(getParentShell(),
                                    Messages.EditBlackboardUtil_ignore_change,
                                    Messages.EditBlackboardUtil_changes_will_be_overwritten);
                            if (ok) {
                                okPressed();
                            }
                            break;

                        default:
                            cancelPressed();
                            break;
                        }
                    }

                    public void okPressed() {
                        dirtyAreas.remove(layer);
                        super.okPressed();
                    }
                };
                dialog.setBlockOnOpen(true);
                dialog.open();
            } finally {
                blackboardLock.unlock();
                dialog = null;
            }

        }
    });
}

From source file:org.eclipse.team.internal.ccvs.ui.repo.CVSRepositoryPropertiesPage.java

License:Open Source License

private boolean performConnectionInfoChanges() {
    // Set the caching mode of the location
    if (!connectionInfoChanged) {
        location.setAllowCaching(allowCaching);
        if (!passwordChanged) {
            ((CVSRepositoryLocation) location).updateCache();
        }// w  w  w.  j av  a2s.  com
    }
    // Don't do anything else if there wasn't a password or connection change
    if (!passwordChanged && !connectionInfoChanged)
        return true;

    try {
        // Check if the password was the only thing to change.
        if (passwordChanged && !connectionInfoChanged) {
            CVSRepositoryLocation oldLocation = (CVSRepositoryLocation) location;
            oldLocation.setPassword(getNewPassword());
            if (allowCaching) {
                oldLocation.updateCache();
            }
            passwordChanged = false;
            return true;
        }

        // Otherwise change the connection info and the password
        // This operation is done inside a workspace operation in case the sharing
        // info for existing projects is changed
        if (!(location.getHost().equals(hostText.getText())
                && location.getRootDirectory().equals(pathText.getText()))) {
            // The host or path has changed
            if (!MessageDialog.openConfirm(getShell(), CVSUIMessages.CVSRepositoryPropertiesPage_0,
                    CVSUIMessages.CVSRepositoryPropertiesPage_1)) {
                return false;
            }
        }
        final boolean[] result = new boolean[] { false };
        final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell());
        progressMonitorDialog.run(false, false, new WorkspaceModifyOperation(null) {
            public void execute(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                try {
                    // Create a new repository location with the new information
                    CVSRepositoryLocation newLocation = CVSRepositoryLocation
                            .fromProperties(createProperties());
                    newLocation.setEncoding(location.getEncoding());
                    location.setAllowCaching(allowCaching);
                    try {
                        // For each project shared with the old location, set connection info to the new one
                        List projects = new ArrayList();
                        IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        for (int i = 0; i < allProjects.length; i++) {
                            RepositoryProvider teamProvider = RepositoryProvider.getProvider(allProjects[i],
                                    CVSProviderPlugin.getTypeId());
                            if (teamProvider != null) {
                                CVSTeamProvider cvsProvider = (CVSTeamProvider) teamProvider;
                                if (cvsProvider.getCVSWorkspaceRoot().getRemoteLocation().equals(location)) {
                                    projects.add(allProjects[i]);
                                }
                            }
                        }
                        if (projects.size() > 0) {
                            // To do: warn the user
                            DetailsDialogWithProjects dialog = new DetailsDialogWithProjects(
                                    progressMonitorDialog.getShell(),
                                    CVSUIMessages.CVSRepositoryPropertiesPage_Confirm_Project_Sharing_Changes_1,
                                    CVSUIMessages.CVSRepositoryPropertiesPage_There_are_projects_in_the_workspace_shared_with_this_repository_2,
                                    NLS.bind(CVSUIMessages.CVSRepositoryPropertiesPage_sharedProject,
                                            new String[] { location.toString() }),
                                    (IProject[]) projects.toArray(new IProject[projects.size()]), true,
                                    Dialog.DLG_IMG_WARNING);
                            int r = dialog.open();
                            if (r != Window.OK) {
                                result[0] = false;
                                return;
                            }
                            monitor.beginTask(null, 1000 * projects.size());
                            try {
                                Iterator it = projects.iterator();
                                while (it.hasNext()) {
                                    IProject project = (IProject) it.next();
                                    RepositoryProvider teamProvider = RepositoryProvider.getProvider(project,
                                            CVSProviderPlugin.getTypeId());
                                    CVSTeamProvider cvsProvider = (CVSTeamProvider) teamProvider;
                                    cvsProvider.setRemoteRoot(newLocation, Policy.subMonitorFor(monitor, 1000));
                                }
                            } finally {
                                monitor.done();
                            }
                        }

                        // Dispose the old repository location
                        CVSUIPlugin.getPlugin().getRepositoryManager().replaceRepositoryLocation(location,
                                newLocation);

                    } finally {
                        // Even if we failed, ensure that the new location appears in the repo view.
                        newLocation = (CVSRepositoryLocation) KnownRepositories.getInstance().addRepository(
                                newLocation,
                                !KnownRepositories.getInstance().isKnownRepository(newLocation.getLocation()));
                    }

                    // Set the location of the page to the new location in case Apply was chosen
                    location = newLocation;
                    connectionInfoChanged = false;
                    passwordChanged = false;
                } catch (TeamException e) {
                    throw new InvocationTargetException(e);
                }
                result[0] = true;
            }
        });
        return result[0];
    } catch (InvocationTargetException e) {
        handle(e);
    } catch (InterruptedException e) {
    }
    return false; /* we only get here if an exception occurred */
}

From source file:raptor.swt.RaptorImageRegistry.java

License:BSD License

/**
 * Returns the image associated with the given key in this registry, or
 * <code>null</code> if none.
 * // w w  w  .ja  v  a 2 s .  c  om
 * @param key
 *            the key
 * @return the image, or <code>null</code> if none
 */
@SuppressWarnings({ "deprecation" })
public Image get(String key) {

    // can be null
    if (key == null) {
        return null;
    }

    if (display != null) {
        /**
         * NOTE, for backwards compatibility the following images are
         * supported here, they should never be disposed, hence we
         * explicitly return them rather then registering images that SWT
         * will dispose.
         * 
         * Applications should go direclty to SWT for these icons.
         * 
         * @see Display.getSystemIcon(int ID)
         */
        int swtKey = -1;
        if (key.equals(Dialog.DLG_IMG_INFO)) {
            swtKey = SWT.ICON_INFORMATION;
        }
        if (key.equals(Dialog.DLG_IMG_QUESTION)) {
            swtKey = SWT.ICON_QUESTION;
        }
        if (key.equals(Dialog.DLG_IMG_WARNING)) {
            swtKey = SWT.ICON_WARNING;
        }
        if (key.equals(Dialog.DLG_IMG_ERROR)) {
            swtKey = SWT.ICON_ERROR;
        }
        // if we actually just want to return an SWT image do so without
        // looking in the registry
        if (swtKey != -1) {
            final Image[] image = new Image[1];
            final int id = swtKey;
            display.syncExec(new RaptorRunnable() {
                @Override
                public void execute() {
                    image[0] = display.getSystemImage(id);
                }
            });
            return image[0];
        }
    }

    Entry entry = getEntry(key);
    if (entry == null) {
        return null;
    }

    if (entry.image == null) {
        entry.image = manager.createImageWithDefault(entry.descriptor);
    }

    return entry.image;
}