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

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

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog 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:org.eclipse.e4.xwt.vex.palette.customize.actions.AddCustomizePaletteAction.java

License:Open Source License

/**
 * Opens the customize palette dialog/*from   ww  w.j  a  v  a  2s .  c  o m*/
 * 
 * @see org.eclipse.jface.action.Action#run()
 */
public void run() {
    Dialog customizeDialog;

    if (invokeType == InvokeType.MenuAdd) {
        customizeDialog = new CustomizePaletteDialog(InvokeType.MenuAdd, null, null);
    } else { // drad add
        customizeDialog = new CustomizePaletteDialog(InvokeType.DragAdd, null, selectionText);
    }
    customizeDialog.open();
}

From source file:org.eclipse.e4.xwt.vex.palette.customize.actions.ModifyCustomizeComponentAction.java

License:Open Source License

@Override
public void run() {
    super.run();// w  w  w  . ja  v  a  2 s  .  c  o m
    // modify customize component
    // CustomizeComponentFactory customizeComponentFactory = CustomizeComponentFactory
    // .getCustomizeComponentFactory();
    Dialog customizeDialog = new CustomizePaletteDialog(InvokeType.Modify, selectComponentName, null);
    customizeDialog.open();
}

From source file:org.eclipse.ecf.ui.screencapture.ScreenCaptureJob.java

License:Open Source License

public IStatus runInUIThread(IProgressMonitor monitor) {
    final Display display = getDisplay();
    final GC context = new GC(display);
    final Rectangle displayBounds = display.getBounds();
    final Image image = new Image(display, displayBounds);
    context.copyArea(image, displayBounds.x, displayBounds.y);
    context.dispose();/*  ww  w .ja  v a 2  s  .  c  om*/

    final Shell shell = new Shell(display, SWT.NO_TRIM);
    shell.setLayout(new FillLayout());
    shell.setBounds(displayBounds);

    crossCursor = new Cursor(display, SWT.CURSOR_CROSS);
    shell.setCursor(crossCursor);

    gc = new GC(shell);

    shell.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.drawImage(image, 0, 0);
        }
    });
    shell.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.ESC)
                shell.close();
        }

        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.ESC)
                shell.close();
        }
    });
    shell.addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent e) {
            isDragging = true;
            downX = e.x;
            downY = e.y;
        }

        public void mouseUp(MouseEvent e) {
            isDragging = false;
            final int width = Math.max(downX, e.x) - Math.min(downX, e.x);
            final int height = Math.max(downY, e.y) - Math.min(downY, e.y);
            if (width != 0 && height != 0) {
                final Image copy = new Image(display, width, height);
                gc.copyArea(copy, Math.min(downX, e.x), Math.min(downY, e.y));
                blackColor.dispose();
                whiteColor.dispose();
                final Dialog dialog = new ScreenCaptureConfirmationDialog(shell, targetID, nickName, copy,
                        width, height, imageSender);
                dialog.open();

                shell.close();
                copy.dispose();
            }
        }
    });

    shell.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            if (isDragging) {
                gc.drawImage(image, 0, 0);
                gc.setForeground(blackColor);
                gc.drawRectangle(downX, downY, e.x - downX, e.y - downY);
                gc.setForeground(whiteColor);
                gc.drawRectangle(downX - 1, downY - 1, e.x - downX + 2, e.y - downY + 2);
            }
        }
    });

    shell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            image.dispose();
            crossCursor.dispose();
            gc.dispose();
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchConfiguredRemoteAction.java

License:Open Source License

/**
 * Runs this action/*from  www .j a v a 2s.  c  o  m*/
 * <p>
 *
 * @param shell
 *            a shell may be null; if provided, a pop up will be displayed
 *            indicating the fetch result; if Exceptions occur, these will
 *            be displayed
 *
 */
public void run(final Shell shell) {
    final RemoteConfig config;
    Exception prepareException = null;
    final Transport transport;
    try {
        config = new RemoteConfig(repository.getConfig(), remoteName);
        if (config.getURIs().isEmpty()) {
            throw new IOException(
                    NLS.bind(UIText.FetchConfiguredRemoteAction_NoUrisDefinedMessage, remoteName));
        }
        if (config.getFetchRefSpecs().isEmpty()) {
            throw new IOException(
                    NLS.bind(UIText.FetchConfiguredRemoteAction_NoSpecsDefinedMessage, remoteName));
        }
        transport = Transport.open(repository, config);
    } catch (URISyntaxException e) {
        prepareException = e;
        return;
    } catch (IOException e) {
        prepareException = e;
        return;
    } finally {
        if (prepareException != null)
            Activator.handleError(prepareException.getMessage(), prepareException, shell != null);
    }

    Job job = new Job(
            "Fetch from " + repository.getDirectory().getParentFile().getName() + " - " + remoteName) { //$NON-NLS-1$ //$NON-NLS-2$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final FetchResult result;
            Exception fetchException = null;
            try {
                result = transport.fetch(new EclipseGitProgressTransformer(monitor), config.getFetchRefSpecs());
            } catch (final NotSupportedException e) {
                fetchException = e;
                return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_fetchNotSupported,
                        e);
            } catch (final TransportException e) {
                if (monitor.isCanceled())
                    return Status.CANCEL_STATUS;
                fetchException = e;
                return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_transportError, e);
            } finally {
                if (fetchException != null)
                    Activator.handleError(fetchException.getMessage(), fetchException, shell != null);
            }
            if (shell != null) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        Dialog dialog = new FetchResultDialog(shell, repository, result,
                                repository.getDirectory().getParentFile().getName() + " - " + remoteName); //$NON-NLS-1$
                        dialog.open();
                    }
                });
            }
            return Status.OK_STATUS;
        }

    };

    job.setUser(true);
    job.schedule();
}

From source file:org.eclipse.egit.ui.internal.push.PushConfiguredRemoteAction.java

License:Open Source License

/**
 * Runs this action//from   ww w  .ja  v  a2s.  c om
 * <p>
 *
 * @param shell
 *            a shell may be null; if provided, a pop up will be displayed
 *            indicating the fetch result
 * @param dryRun
 *
 */
public void run(final Shell shell, boolean dryRun) {
    RemoteConfig config;
    PushOperationSpecification spec;
    Exception pushException = null;
    final PushOperation op;
    try {
        config = new RemoteConfig(repository.getConfig(), remoteName);
        // config.getPushURIs returns a unmodifiable list
        List<URIish> pushURIs = new ArrayList<URIish>();
        pushURIs.addAll(config.getPushURIs());
        if (pushURIs.isEmpty() && !config.getURIs().isEmpty())
            pushURIs.add(config.getURIs().get(0));
        if (pushURIs.isEmpty()) {
            throw new IOException(NLS.bind(UIText.PushConfiguredRemoteAction_NoUrisMessage, remoteName));
        }
        final Collection<RefSpec> pushSpecs = config.getPushRefSpecs();
        if (pushSpecs.isEmpty()) {
            throw new IOException(NLS.bind(UIText.PushConfiguredRemoteAction_NoSpecDefined, remoteName));
        }
        final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository, pushSpecs,
                null);
        if (updates.isEmpty()) {
            throw new IOException(
                    NLS.bind(UIText.PushConfiguredRemoteAction_NoUpdatesFoundMessage, remoteName));
        }

        spec = new PushOperationSpecification();
        for (final URIish uri : pushURIs)
            spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
        int timeout = Activator.getDefault().getPreferenceStore()
                .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
        op = new PushOperation(repository, spec, dryRun, config, timeout);

    } catch (URISyntaxException e) {
        pushException = e;
        return;
    } catch (IOException e) {
        pushException = e;
        return;
    } finally {
        if (pushException != null)
            Activator.handleError(pushException.getMessage(), pushException, shell != null);
    }

    final Job job = new Job(
            "Push to " + repository.getDirectory().getParentFile().getName() + " - " + remoteName) { //$NON-NLS-1$ //$NON-NLS-2$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                op.run(monitor);
                final PushOperationResult res = op.getOperationResult();
                if (shell != null) {
                    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                        public void run() {
                            final Dialog dialog = new PushResultDialog(shell, repository, res,
                                    repository.getDirectory().getParentFile().getName() + " - " + remoteName); //$NON-NLS-1$
                            dialog.open();
                        }
                    });
                }
                return Status.OK_STATUS;
            } catch (InvocationTargetException e) {
                return new Status(IStatus.ERROR, Activator.getPluginId(), e.getCause().getMessage(), e);
            }
        }

        @Override
        public boolean belongsTo(Object family) {
            if (family.equals(JobFamilies.PUSH))
                return true;
            return super.belongsTo(family);
        }

    };

    job.setUser(true);
    job.schedule();
}

From source file:org.eclipse.emf.cdo.internal.ui.actions.RollbackTransactionAction.java

License:Open Source License

@Override
protected void preRun() throws Exception {
    CDOTransaction transaction = (CDOTransaction) getView();
    Dialog dialog = new RollbackTransactionDialog(getPage(), TITLE, "Choose how to rollback this transaction.",
            transaction);// w w  w .  j  a  v  a  2s  . c o  m
    switch (dialog.open()) {
    case RollbackTransactionDialog.REMOTE:
        remote = true;
        break;
    case RollbackTransactionDialog.LOCAL:
        remote = false;
        break;
    default:
        cancel();
        break;
    }
}

From source file:org.eclipse.emf.cdo.internal.ui.editor.CDOEditor.java

License:Open Source License

/**
 * @ADDED//w w w  . ja v  a2  s .  com
 */
@Override
public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running activity
    // that modifies the workbench.
    //
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
        // This is the method that gets invoked when the operation runs.
        //
        @Override
        public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                        && !editingDomain.isReadOnly(resource)) {
                    try {
                        savedResources.add(resource);
                        resource.save(saveOptions);
                    } catch (final TransactionException exception) {
                        final Shell shell = getSite().getShell();
                        shell.getDisplay().syncExec(new Runnable() {
                            public void run() {
                                CDOTransaction transaction = (CDOTransaction) view;
                                Dialog dialog = new RollbackTransactionDialog(getEditorSite().getPage(),
                                        "Transaction Error", exception.getMessage(), transaction);
                                switch (dialog.open()) {
                                case RollbackTransactionDialog.REMOTE:
                                    transaction.rollback(true);
                                    break;
                                case RollbackTransactionDialog.LOCAL:
                                    transaction.rollback(false);
                                    break;
                                }
                            }
                        });
                    } catch (Exception exception) {
                        OM.LOG.error(exception);
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }

                    first = false;
                }
            }
        }
    };

    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        //
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

        // Refresh the necessary state.
        //
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        PluginDelegator.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:org.eclipse.emf.cdo.ui.CDOInteractiveExceptionHandler.java

License:Open Source License

/**
 * @since 4.0/*from  w  w w . j a  v  a 2  s .c o  m*/
 */
public void handleException(final CDOSession session, final int attempt, Exception exception) throws Exception {
    final Exception[] result = { exception };
    Runnable runnable = new Runnable() {
        public void run() {
            Dialog dialog = createDialog(session, attempt, result[0]);
            boolean retry = dialog.open() == Dialog.OK;
            if (retry) {
                result[0] = null;
            }
        }
    };

    Display display = UIUtil.getDisplay();
    if (display != null && !display.isDisposed()) {
        if (display.getThread() == Thread.currentThread()) {
            runnable.run();
        } else {
            display.syncExec(runnable);
        }
    }

    if (result[0] != null) {
        throw result[0];
    }
}

From source file:org.eclipse.emf.compare.ui.internal.ModelComparator.java

License:Open Source License

/**
 * This will load the resources held by <code>input</code>.
 * //from   w w w  .  ja  v  a  2s  .  co m
 * @param input
 *            CompareInput which holds the resources to be loaded.
 * @return <code>true</code> if the given models have been successfully loaded, <code>false</code>
 *         otherwise.
 */
public boolean loadResources(ICompareInput input) {
    if (ancestorElement != input.getAncestor() || leftElement != input.getLeft()
            || rightElement != input.getRight()) {
        clear();
        leftElement = input.getLeft();
        rightElement = input.getRight();
        ancestorElement = input.getAncestor();

        // check whether this comparison hasn't already been played (workaround for #345415)
        if (handleResourceMapping(input)) {
            loadingSucceeded = true;
            return loadingSucceeded;
        }

        try {
            // This will be sufficient when comparing local resources
            loadingSucceeded = handleLocalResources(leftElement, rightElement, ancestorElement);
            // If resources weren't local, iterates through the registry to find
            // a proper team handler
            if (!loadingSucceeded) {
                final Iterator<TeamHandlerDescriptor> handlerDescriptorIterator = CACHED_HANDLERS.iterator();
                while (handlerDescriptorIterator.hasNext()) {
                    final AbstractTeamHandler handler = handlerDescriptorIterator.next().getHandlerInstance();
                    loadingSucceeded |= handler.loadResources(input);
                    if (loadingSucceeded) {
                        comparisonHandler = handler;
                        break;
                    }
                }
            }
            // We didn't find a proper handler, use a generic one
            if (!loadingSucceeded) {
                loadingSucceeded |= handleGenericResources(leftElement, rightElement, ancestorElement);
            }
            /*
             * The generic handler should work for any EMF resources. If we're here, no exception has been
             * thrown and loading ended accurately
             */
            loadingSucceeded = true;
        } catch (final IOException e) {
            final String dialogMessage;
            if (IS_LESS_GANYMEDE) {
                dialogMessage = EMFCompareUIMessages.getString("ModelComparator.ResourceLoadingFailure"); //$NON-NLS-1$
            } else {
                dialogMessage = EMFCompareUIMessages
                        .getString("ModelComparator.ResourceLoadingFailureGanymede"); //$NON-NLS-1$
            }
            final Dialog dialog = new CompareErrorDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Comparison failed", //$NON-NLS-1$
                    dialogMessage, new Status(IStatus.ERROR, EMFCompareUIPlugin.PLUGIN_ID, e.getMessage(), e));
            final int buttonPressed = dialog.open();
            if (buttonPressed == CompareErrorDialog.COMPARE_AS_TEXT_ID) {
                final Set<Object> set = new HashSet<Object>();
                final CompareEditorInput editorInput = (CompareEditorInput) compareConfiguration.getContainer();
                // value of the 3.3 and 3.4 "ICompareAsText.PROP_TEXT_INPUT"
                compareConfiguration.setProperty("org.eclipse.compare.TextInputs", set); //$NON-NLS-1$
                set.add(editorInput);
                set.add(editorInput.getCompareResult());
                CompareUI.openCompareEditorOnPage(editorInput, null);
            }
        } catch (final CoreException e) {
            EMFComparePlugin.log(e.getStatus());
        }
    } else {
        // input was the same as the last
    }
    return loadingSucceeded;
}

From source file:org.eclipse.emf.ecp.edit.internal.swt.util.DialogOpener.java

License:Open Source License

/**
 * The provided {@link Dialog} is opened and the result is returned via the provided {@link ECPDialogExecutor}.
 * This method searches for a DialogWrapper which will wrap the code in order to allow opening JFace dialogs in RAP.
 *
 * @param dialog the JFace Dialog to open
 * @param callBack the {@link ECPDialogExecutor} called to handle the result
 *//*  ww w  .jav a  2  s  . c om*/
public static void openDialog(Dialog dialog, ECPDialogExecutor callBack) {
    DialogWrapper wrapper = null;
    final IConfigurationElement[] controls = Platform.getExtensionRegistry()
            .getConfigurationElementsFor("org.eclipse.emf.ecp.edit.swt.dialogWrapper"); //$NON-NLS-1$
    for (final IConfigurationElement e : controls) {
        try {
            wrapper = (DialogWrapper) e.createExecutableExtension("class"); //$NON-NLS-1$
            break;
        } catch (final CoreException e1) {
            Activator.logException(e1);
        }
    }
    if (wrapper == null) {
        callBack.handleResult(dialog.open());
        return;
    }
    wrapper.openDialog(dialog, callBack);
}