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();
}
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);
}
Aggregations