Search in sources :

Example 6 with IManagedForm

use of org.eclipse.ui.forms.IManagedForm in project webtools.servertools by eclipse.

the class OverviewEditorPart method validate.

protected void validate() {
    IManagedForm mForm = getManagedForm();
    if (mForm == null)
        return;
    MultiStatus ms = new MultiStatus(ServerUIPlugin.PLUGIN_ID, 0, "Validating Overview Part", null);
    mForm.getMessageManager().removeMessage("name", serverName);
    if (server != null && serverName != null) {
        if (ServerPlugin.isNameOnlyInUse(server, serverName.getText().trim())) {
            mForm.getMessageManager().addMessage("name", Messages.errorDuplicateName, null, IMessageProvider.ERROR, serverName);
            ms.add(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorDuplicateName));
        }
    }
    if (serverConfiguration != null) {
        mForm.getMessageManager().removeMessage("config", serverConfiguration);
        if (server != null && server.getServerType() != null && server.getServerType().hasServerConfiguration()) {
            IFolder folder = getServer().getServerConfiguration();
            if (folder == null || !folder.exists()) {
                IProject project = null;
                if (folder != null)
                    project = folder.getProject();
                if (project != null && project.exists() && !project.isOpen()) {
                    mForm.getMessageManager().addMessage("config", NLS.bind(Messages.errorConfigurationNotAccessible, project.getName()), null, IMessageProvider.ERROR, serverConfiguration);
                    ms.add(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, NLS.bind(Messages.errorConfigurationNotAccessible, project.getName())));
                } else {
                    mForm.getMessageManager().addMessage("config", Messages.errorMissingConfiguration, null, IMessageProvider.ERROR, serverConfiguration);
                    ms.add(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorMissingConfiguration));
                }
            }
        }
    }
    validationStatus = (ms.isOK() ? Status.OK_STATUS : ms);
    mForm.getMessageManager().update();
}
Also used : IManagedForm(org.eclipse.ui.forms.IManagedForm)

Example 7 with IManagedForm

use of org.eclipse.ui.forms.IManagedForm 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)

Example 8 with IManagedForm

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

the class BundleContentPage method createFormContent.

@Override
protected void createFormContent(IManagedForm managedForm) {
    FormToolkit toolkit = managedForm.getToolkit();
    managedForm.setInput(model);
    ScrolledForm scrolledForm = managedForm.getForm();
    scrolledForm.setText("Bundle Content");
    Form form = scrolledForm.getForm();
    toolkit.decorateFormHeading(form);
    form.addMessageHyperlinkListener(new MessageHyperlinkAdapter(getEditor()));
    Composite body = form.getBody();
    // Create controls
    MDSashForm sashForm = new MDSashForm(body, SWT.HORIZONTAL, managedForm);
    sashForm.setSashWidth(6);
    toolkit.adapt(sashForm, false, false);
    Composite leftPanel = toolkit.createComposite(sashForm);
    createLeftPanel(managedForm, leftPanel);
    Composite rightPanel = toolkit.createComposite(sashForm);
    createRightPanel(managedForm, rightPanel);
    sashForm.setWeights(new int[] { 1, 1 });
    sashForm.hookResizeListener();
    // Layout
    body.setLayout(new FillLayout());
}
Also used : MessageHyperlinkAdapter(bndtools.utils.MessageHyperlinkAdapter) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) MDSashForm(bndtools.editor.common.MDSashForm) IManagedForm(org.eclipse.ui.forms.IManagedForm) Form(org.eclipse.ui.forms.widgets.Form) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) MDSashForm(bndtools.editor.common.MDSashForm) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 9 with IManagedForm

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

the class FormPartJavaSearchContext method getFormPage.

private IFormPage getFormPage() {
    IManagedForm managedForm = formPart.getManagedForm();
    if (managedForm == null)
        return null;
    Object container = managedForm.getContainer();
    if (!(container instanceof IFormPage))
        return null;
    return (IFormPage) container;
}
Also used : IManagedForm(org.eclipse.ui.forms.IManagedForm) IFormPage(org.eclipse.ui.forms.editor.IFormPage)

Example 10 with IManagedForm

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

the class WorkspaceMainPart method initialize.

@Override
public void initialize(final IManagedForm form) {
    super.initialize(form);
    final Composite container = (Composite) getSection().getClient();
    // create a layout stack and the first visible component will be an empty component with "waiting" message
    // this will be replaced by real composite once workspace completes
    final StackLayout stackLayout = new StackLayout();
    container.setLayout(stackLayout);
    Composite labelParent = new Composite(container, SWT.NONE);
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginHeight = fillLayout.marginWidth = 10;
    labelParent.setLayout(fillLayout);
    if (!Central.isWorkspaceInited()) {
        Label label = new Label(labelParent, SWT.NONE);
        label.setText("Workspace is loading, please wait...");
        label.setBackground(container.getBackground());
        label.setForeground(container.getForeground());
    }
    stackLayout.topControl = labelParent;
    container.layout();
    Central.onWorkspaceAsync(workspace -> {
        IFile buildFile = Central.getWorkspaceBuildFile();
        if (buildFile == null)
            return;
        Composite contents = new Composite(container, SWT.NONE);
        if (!mainFile) {
            ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
            link.setText("Open main build.bnd file.");
            link.setImage(bndFileImg);
            link.addHyperlinkListener(new FileOpenLinkListener(buildFile.getFullPath()));
        } else {
            IResource[] extFiles;
            IContainer cnfDir = buildFile.getParent();
            IFolder extDir = cnfDir.getFolder(new Path("ext"));
            if (extDir.exists())
                extFiles = extDir.members();
            else
                extFiles = new IResource[0];
            if (extFiles.length > 0) {
                for (IResource extFile : extFiles) {
                    if (extFile.getType() == IResource.FILE && "bnd".equalsIgnoreCase(extFile.getFileExtension())) {
                        ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
                        link.setText("Open " + extFile.getName());
                        link.setImage(extFileImg);
                        link.addHyperlinkListener(new FileOpenLinkListener(extFile.getFullPath()));
                    }
                }
            } else {
                createMissingExtsWarningPanel(contents, form.getToolkit(), extDir.getFullPath());
            }
        }
        stackLayout.topControl = contents;
        container.layout();
    }).onFailure(e -> Plugin.error(Collections.singletonList(e.getMessage())));
}
Also used : IFolder(org.eclipse.core.resources.IFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) IContainer(org.eclipse.core.resources.IContainer) SectionPart(org.eclipse.ui.forms.SectionPart) IPath(org.eclipse.core.runtime.IPath) Plugin(bndtools.Plugin) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) AbstractUIPlugin(org.eclipse.ui.plugin.AbstractUIPlugin) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Section(org.eclipse.ui.forms.widgets.Section) FileEditorInput(org.eclipse.ui.part.FileEditorInput) StackLayout(org.eclipse.swt.custom.StackLayout) PlatformUI(org.eclipse.ui.PlatformUI) Central(bndtools.central.Central) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IManagedForm(org.eclipse.ui.forms.IManagedForm) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Color(org.eclipse.swt.graphics.Color) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Collections(java.util.Collections) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) StackLayout(org.eclipse.swt.custom.StackLayout) Label(org.eclipse.swt.widgets.Label) FillLayout(org.eclipse.swt.layout.FillLayout) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IManagedForm (org.eclipse.ui.forms.IManagedForm)15 Composite (org.eclipse.swt.widgets.Composite)6 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)5 GridData (org.eclipse.swt.layout.GridData)4 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)4 GridLayout (org.eclipse.swt.layout.GridLayout)3 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)3 MDSashForm (bndtools.editor.common.MDSashForm)2 MessageHyperlinkAdapter (bndtools.utils.MessageHyperlinkAdapter)2 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Button (org.eclipse.swt.widgets.Button)2 Control (org.eclipse.swt.widgets.Control)2 PartInitException (org.eclipse.ui.PartInitException)2 IFormPage (org.eclipse.ui.forms.editor.IFormPage)2 Form (org.eclipse.ui.forms.widgets.Form)2 Section (org.eclipse.ui.forms.widgets.Section)2