Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog

Introduction

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

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:diva.presentation.DivaEditor.java

License:Apache License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model
 * file. <!-- begin-user-doc --> <!-- end-user-doc -->
 * //from w  ww .ja v a  2  s. co  m
 * @generated
 */
@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);
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);

    // 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 {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception 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();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        DiVA_visitorEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:DiversityBenchmark.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();//from  w  ww . java  2 s .  co m
    dialog.run(true, true, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                Object clientObject = contribution.getObject();
            }
        }
    });

    pmContext.dispose();
}

From source file:e4rcp.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();/*  www  .  ja  v  a2s.c o  m*/
    dialog.run(true, true, new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                //               Object clientObject = contribution.getObject();
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
                //                     pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:eachonce.presentation.EachonceEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->/*  w w w. j a v  a 2  s. com*/
 * <!-- end-user-doc -->
 * @generated
 */
@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 {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception 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();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        EachonceEditPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:edu.duke.cs.ambient.internal.ui.actions.AmbientRunAction.java

License:Open Source License

/**
 * @param search//from   w  ww  . ja  va 2  s. c  o  m
 *            the java elements to search for a main type
 * @param mode
 *            the mode to launch in
 * @param whether
 *            activated on an editor (or from a selection in a myViewer)
 */
public void searchAndLaunch(Object[] search, String mode, boolean editor) {
    IType[] types = null;
    if (search != null) {
        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            MainMethodSearchEngine engine = new MainMethodSearchEngine();

            IJavaSearchScope scope = SearchEngine.createJavaSearchScope((IJavaElement[]) search);
            types = engine.searchMainMethods(dialog, scope, false);
        } catch (InterruptedException e) {
            return;
        } catch (java.lang.reflect.InvocationTargetException e) {
            return;
        }
        IType type = null;
        if (types.length == 0) {
            String message = null;
            if (editor) {
                message = "The active editor does not contain a main type";// LauncherMessages.getString("JavaApplicationLaunchShortcut.The_active_editor_does_not_contain_a_main_type._1");
                // TODO find out what all the old messages really were                                                         // //$NON-NLS-1$
            } else {
                message = "The selection does not contain a main type";// LauncherMessages.getString("JavaApplicationLaunchShortcut.The_selection_does_not_contain_a_main_type._2");
                                                                       // //$NON-NLS-1$
            }
            MessageDialog.openError(getShell(),
                    "Launch failed"/* LauncherMessages.getString("JavaApplicationAction.Launch_failed_7") */, //$NON-NLS-1$
                    message);
        } else if (types.length > 1) {
            type = chooseType(types, mode);
        } else {
            type = types[0];
        }
        if (type != null) {
            launch(type, mode);
        }
    }

}

From source file:edu.kit.joana.ui.ifc.sdg.latticeeditor.ui.FlowEditor.java

License:Open Source License

/**
 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
 *///from  ww w . j av a 2 s.c  o  m
public void doSaveAs() {
    SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
    dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
    dialog.open();
    IPath path = dialog.getResult();

    if (path == null)
        return;

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IFile file = workspace.getRoot().getFile(path);

    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
        public void execute(final IProgressMonitor monitor) throws CoreException {
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                createOutputStream(out);
                file.create(new ByteArrayInputStream(out.toByteArray()), true, monitor);
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    try {
        new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
        setInput(new FileEditorInput(file));
        getCommandStack().markSaveLocation();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.kit.joana.ui.ifc.sdg.latticeeditor.ui.LatticeEditor.java

License:Open Source License

/**
 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
 *///from  w  ww. ja  va 2  s  .c om
public void doSaveAs() {

    SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
    dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
    dialog.open();
    IPath path = dialog.getResult();

    if (path == null)
        return;

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IFile file = workspace.getRoot().getFile(path);

    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
        public void execute(final IProgressMonitor monitor) throws CoreException {
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                createOutputStream(out);
                file.create(new ByteArrayInputStream(out.toByteArray()), true, monitor);
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    try {
        new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
        setInput(new FileEditorInput(file));
        getCommandStack().markSaveLocation();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.toronto.cs.se.mmint.mid.editor.presentation.EditorEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->// w  ww  .  j a va 2 s  . c  om
 * <!-- end-user-doc -->
 * @generated
 */
@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);
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);

    // 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 {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception 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();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        MIDEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:edu.toronto.cs.se.modelepedia.classdiagram.presentation.ClassDiagramEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->// w w w  .  j  av  a 2 s  .  c o  m
 * <!-- end-user-doc -->
 * @generated
 */
@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);
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);

    // 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 {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception 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();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        ClassDiagramEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}

From source file:edu.toronto.cs.se.modelepedia.classdiagram_mavo.presentation.ClassDiagram_MAVOEditor.java

License:Open Source License

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->//from  w  ww  .j  a v a  2s . c  om
 * <!-- end-user-doc -->
 * @generated
 */
@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);
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED);

    // 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 {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception 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();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        //
        ClassDiagram_MAVOEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}