Search in sources :

Example 1 with IFormPart

use of org.eclipse.ui.forms.IFormPart in project liferay-ide by liferay.

the class IDEFormPage method createFormContent.

protected void createFormContent(IManagedForm managedForm) {
    ScrolledForm form = managedForm.getForm();
    FormToolkit toolkit = managedForm.getToolkit();
    toolkit.decorateFormHeading(form.getForm());
    IToolBarManager manager = form.getToolBarManager();
    getFormEditor().contributeToToolbar(manager);
    IFormPart[] parts = managedForm.getParts();
    for (int i = 0; i < parts.length; i++) {
        if (parts[i] instanceof IAdaptable) {
            IAdaptable adapter = (IAdaptable) parts[i];
            IAction[] actions = (IAction[]) adapter.getAdapter(IAction[].class);
            if (actions != null) {
                for (int j = 0; j < actions.length; j++) {
                    form.getToolBarManager().add(actions[j]);
                }
            }
        }
    }
    form.updateToolBar();
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IAction(org.eclipse.jface.action.IAction) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) IFormPart(org.eclipse.ui.forms.IFormPart)

Example 2 with IFormPart

use of org.eclipse.ui.forms.IFormPart in project bndtools by bndtools.

the class BndEditor method resolveRunBundles.

public Promise<IStatus> resolveRunBundles(IProgressMonitor monitor, boolean onSave) {
    final Shell shell = getEditorSite().getShell();
    final IFile file = ResourceUtil.getFile(getEditorInput());
    if (file == null) {
        MessageDialog.openError(shell, "Resolution Error", "Unable to run resolution because the file is not in the workspace.");
        reallySave(monitor);
        return Central.promiseFactory().resolved(Status.CANCEL_STATUS);
    }
    Job loadWorkspaceJob = new Job("Loading workspace...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            if (monitor == null)
                monitor = new NullProgressMonitor();
            monitor.beginTask("Loading workspace", 2);
            try {
                Central.getWorkspace();
                monitor.worked(1);
                modelReady.getValue();
                return Status.OK_STATUS;
            } catch (Exception e) {
                return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to initialize workspace.", e);
            } finally {
                monitor.done();
            }
        }
    };
    final UIJob runResolveInUIJob = new UIJob("Resolve") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            // dirty state to the model
            for (Object pageObj : pages) {
                if (pageObj instanceof IFormPage) {
                    IFormPage formPage = (IFormPage) pageObj;
                    IManagedForm form = formPage.getManagedForm();
                    if (form != null) {
                        IFormPart[] formParts = form.getParts();
                        for (IFormPart formPart : formParts) {
                            if (formPart.isDirty())
                                formPart.commit(false);
                        }
                    }
                }
            }
            if (sourcePage.isActive() && sourcePage.isDirty()) {
                sourcePage.commit(false);
            }
            // Create resolver job and pre-validate
            final ResolveJob job = new ResolveJob(model);
            IStatus validation = job.validateBeforeRun();
            if (!validation.isOK()) {
                if (onSave)
                    reallySave(monitor);
                return validation;
            }
            // Add operation to perform at the end of resolution (i.e. display
            // results and actually save the file)
            final UIJob completionJob = new UIJob(shell.getDisplay(), "Display Resolution Results") {

                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    ResolutionResult result = job.getResolutionResult();
                    ResolutionWizard wizard = new ResolutionWizard(model, file, result);
                    if (onSave) {
                        // We are in auto-resolve-on-save, only show the dialog if there is a problem
                        wizard.setAllowFinishUnresolved(true);
                        wizard.setPreserveRunBundlesUnresolved(true);
                        if (result.getOutcome() != ResolutionResult.Outcome.Resolved) {
                            WizardDialog dialog = new DuringSaveWizardDialog(shell, wizard);
                            dialog.create();
                            dialog.setErrorMessage("Resolve Failed! Saving now will not update the Run Bundles.");
                            if (dialog.open() == Window.OK)
                                reallySave(monitor);
                        } else {
                            wizard.performFinish();
                            reallySave(monitor);
                        }
                    } else {
                        // This is an interactive resolve, always show the dialog
                        boolean dirtyBeforeResolve = isDirty();
                        WizardDialog dialog = new WizardDialog(shell, wizard);
                        if (dialog.open() == Window.OK && !dirtyBeforeResolve) {
                            // save changes immediately if there were no unsaved changes before the resolve
                            reallySave(monitor);
                        }
                    }
                    return Status.OK_STATUS;
                }
            };
            job.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    completionJob.schedule();
                }
            });
            // Start job
            job.setUser(true);
            job.schedule();
            return Status.OK_STATUS;
        }
    };
    runResolveInUIJob.setUser(true);
    return JobUtil.chainJobs(loadWorkspaceJob, runResolveInUIJob);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ResolutionWizard(org.bndtools.core.resolve.ui.ResolutionWizard) IManagedForm(org.eclipse.ui.forms.IManagedForm) ResolutionResult(org.bndtools.core.resolve.ResolutionResult) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IFormPage(org.eclipse.ui.forms.editor.IFormPage) ResolveJob(org.bndtools.core.resolve.ResolveJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) PartInitException(org.eclipse.ui.PartInitException) BadLocationException(aQute.bnd.properties.BadLocationException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFormPart(org.eclipse.ui.forms.IFormPart) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) ResolveJob(org.bndtools.core.resolve.ResolveJob) UIJob(org.eclipse.ui.progress.UIJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

IFormPart (org.eclipse.ui.forms.IFormPart)2 BadLocationException (aQute.bnd.properties.BadLocationException)1 IOException (java.io.IOException)1 ResolutionResult (org.bndtools.core.resolve.ResolutionResult)1 ResolveJob (org.bndtools.core.resolve.ResolveJob)1 ResolutionWizard (org.bndtools.core.resolve.ui.ResolutionWizard)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 IAction (org.eclipse.jface.action.IAction)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Shell (org.eclipse.swt.widgets.Shell)1