use of org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchPage method extendPerspectives.
/**
* Extends the perspectives within the given stack with action set contributions
* from the <code>perspectiveExtensions</code> extension point.
*
* @param perspectiveStack the stack that contain the perspectives to be
* extended
*/
private void extendPerspectives(MPerspectiveStack perspectiveStack) {
for (MPerspective perspective : perspectiveStack.getChildren()) {
String id = perspective.getElementId();
IPerspectiveDescriptor desc = getWorkbenchWindow().getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id);
if (desc != null) {
MPerspective temporary = modelService.createModelElement(MPerspective.class);
ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService, partService, temporary, desc, this, true);
PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
reader.setIncludeOnlyTags(new String[] { IWorkbenchRegistryConstants.TAG_ACTION_SET });
reader.extendLayout(null, id, modelLayout);
addActionSet(perspective, temporary);
}
}
}
use of org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchPage method createPerspective.
/**
* @param perspective
* @return never null
*/
private MPerspective createPerspective(IPerspectiveDescriptor perspective) {
MPerspective modelPerspective = modelService.createModelElement(MPerspective.class);
// tag it with the same id
modelPerspective.setElementId(perspective.getId());
// instantiate the perspective
IPerspectiveFactory factory = ((PerspectiveDescriptor) perspective).createFactory();
ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService, partService, modelPerspective, perspective, this, true);
factory.createInitialLayout(modelLayout);
PerspectiveTagger.tagPerspective(modelPerspective, modelService);
PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
reader.extendLayout(getExtensionTracker(), perspective.getId(), modelLayout);
return modelPerspective;
}
use of org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchPage method getPerspectiveExtensionActionSets.
ArrayList<String> getPerspectiveExtensionActionSets(String id) {
IPerspectiveDescriptor desc = getWorkbenchWindow().getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id);
if (desc != null) {
MPerspective temporary = modelService.createModelElement(MPerspective.class);
ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService, partService, temporary, desc, this, true);
PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
reader.setIncludeOnlyTags(new String[] { IWorkbenchRegistryConstants.TAG_ACTION_SET });
reader.extendLayout(null, id, modelLayout);
return new ArrayList<>(ModeledPageLayout.getIds(temporary, ModeledPageLayout.ACTION_SET_TAG));
}
return null;
}
use of org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchPage method resetPerspective.
/**
* Resets the layout for the perspective. The active part in the old layout is
* activated in the new layout for consistent user context.
*/
@Override
public void resetPerspective() {
MPerspectiveStack perspStack = getPerspectiveStack();
MPerspective persp = perspStack.getSelectedElement();
if (persp == null)
return;
// HACK!! the 'perspective' field doesn't match reality...
IPerspectiveDescriptor desc = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(persp.getElementId());
if (desc == null)
return;
// send out reset notification
legacyWindow.firePerspectiveChanged(this, desc, CHANGE_RESET);
// collect all the parts under the current perspective
List<MPart> perspectiveParts = modelService.findElements(persp, null, MPart.class, null);
// find the shared area
MUIElement area = findSharedArea();
if (area != null) {
// remove all editors in the shared area from the list of parts
perspectiveParts.removeAll(modelService.findElements(area, CompatibilityEditor.MODEL_ELEMENT_ID, MPart.class, null));
}
List<MPart> dirtyParts = new ArrayList<>();
List<IWorkbenchPart> partsToSave = new ArrayList<>();
// iterate over the list of parts to find dirty parts
for (MPart currentPart : perspectiveParts) {
if (currentPart.isDirty()) {
Object object = currentPart.getObject();
if (object == null) {
continue;
} else if (object instanceof CompatibilityPart) {
IWorkbenchPart workbenchPart = getWrappedPart((CompatibilityPart) object);
if (workbenchPart == null) {
continue;
}
ISaveablePart saveable = SaveableHelper.getSaveable(workbenchPart);
if (saveable == null || !saveable.isSaveOnCloseNeeded()) {
continue;
}
partsToSave.add(workbenchPart);
}
dirtyParts.add(currentPart);
}
}
SaveablesList saveablesList = null;
Object postCloseInfo = null;
if (partsToSave.size() > 0) {
saveablesList = (SaveablesList) getWorkbenchWindow().getService(ISaveablesLifecycleListener.class);
postCloseInfo = saveablesList.preCloseParts(partsToSave, true, this.getWorkbenchWindow());
if (postCloseInfo == null) {
// cancel
// We're not going through with the reset, so it is
// complete.
legacyWindow.firePerspectiveChanged(this, desc, CHANGE_RESET_COMPLETE);
return;
}
}
modelService.resetPerspectiveModel(persp, window);
if (saveablesList != null) {
saveablesList.postClose(postCloseInfo);
}
boolean revert = false;
if (desc instanceof PerspectiveDescriptor) {
PerspectiveDescriptor perspectiveDescriptor = (PerspectiveDescriptor) desc;
revert = perspectiveDescriptor.isPredefined() && !perspectiveDescriptor.hasCustomDefinition();
}
MPerspective dummyPerspective = null;
if (!revert) {
dummyPerspective = (MPerspective) modelService.cloneSnippet(application, desc.getId(), window);
if (dummyPerspective != null) {
handleNullRefPlaceHolders(dummyPerspective, window);
}
}
if (dummyPerspective == null) {
// instantiate a dummy perspective perspective
dummyPerspective = modelService.createModelElement(MPerspective.class);
dummyPerspective.setElementId(persp.getElementId());
IPerspectiveFactory factory = ((PerspectiveDescriptor) desc).createFactory();
ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService, partService, dummyPerspective, desc, this, true);
factory.createInitialLayout(modelLayout);
PerspectiveTagger.tagPerspective(dummyPerspective, modelService);
PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
reader.extendLayout(getExtensionTracker(), desc.getId(), modelLayout);
}
String hiddenItems = dummyPerspective.getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY);
persp.getPersistedState().put(ModeledPageLayout.HIDDEN_ITEMS_KEY, hiddenItems);
legacyWindow.getMenuManager().updateAll(true);
// ((ICoolBarManager2) ((WorkbenchWindow)
// getWorkbenchWindow()).getCoolBarManager2())
// .resetItemOrder();
// Hide placeholders for parts that exist in the 'global' areas
modelService.hideLocalPlaceholders(window, dummyPerspective);
int dCount = dummyPerspective.getChildren().size();
while (dummyPerspective.getChildren().size() > 0) {
MPartSashContainerElement dChild = dummyPerspective.getChildren().remove(0);
persp.getChildren().add(dChild);
}
while (persp.getChildren().size() > dCount) {
MUIElement child = persp.getChildren().get(0);
child.setToBeRendered(false);
persp.getChildren().remove(0);
}
List<MWindow> existingDetachedWindows = new ArrayList<>();
existingDetachedWindows.addAll(persp.getWindows());
// Move any detached windows from template to perspective
while (dummyPerspective.getWindows().size() > 0) {
MWindow detachedWindow = dummyPerspective.getWindows().remove(0);
persp.getWindows().add(detachedWindow);
}
// disposed
for (MWindow detachedWindow : existingDetachedWindows) {
detachedWindow.setToBeRendered(false);
persp.getWindows().remove(detachedWindow);
}
// deactivate and activate other action sets as
Perspective oldPersp = getPerspective(persp);
Perspective dummyPersp = getPerspective(dummyPerspective);
updateActionSets(oldPersp, dummyPersp);
oldPersp.getAlwaysOnActionSets().clear();
oldPersp.getAlwaysOnActionSets().addAll(dummyPersp.getAlwaysOnActionSets());
oldPersp.getAlwaysOffActionSets().clear();
oldPersp.getAlwaysOffActionSets().addAll(dummyPersp.getAlwaysOffActionSets());
modelToPerspectiveMapping.remove(dummyPerspective);
// partly fixing toolbar refresh issue, see bug 383569 comment 10
legacyWindow.updateActionSets();
// migrate the tags
List<String> tags = persp.getTags();
tags.clear();
tags.addAll(dummyPerspective.getTags());
// remove HIDDEN_EXPLICITLY tag from trim elements
List<MTrimElement> trimElements = modelService.findElements(window, null, MTrimElement.class, null);
for (MTrimElement mTrimElement : trimElements) {
mTrimElement.getTags().remove(IPresentationEngine.HIDDEN_EXPLICITLY);
}
partService.requestActivation();
// reset complete
legacyWindow.firePerspectiveChanged(this, desc, CHANGE_RESET_COMPLETE);
UIEvents.publishEvent(UIEvents.UILifeCycle.PERSPECTIVE_RESET, persp);
}
Aggregations