use of org.eclipse.e4.ui.model.application.ui.MGenericStack in project eclipse.platform.ui by eclipse-platform.
the class PartActivationHistory method findActivationCandidate.
/**
* Finds and returns a part that is a valid candidate to be granted activation.
*/
private MPart findActivationCandidate(Collection<MPart> candidates, MPart currentlyActivePart) {
candidates.remove(currentlyActivePart);
MPlaceholder activePlaceholder = partService.getLocalPlaceholder(currentlyActivePart);
for (MPart candidate : candidates) {
// make sure it's rendered and visible
if (isValid(candidate)) {
MPlaceholder placeholder = partService.getLocalPlaceholder(candidate);
MElementContainer<MUIElement> parent = placeholder == null ? candidate.getParent() : placeholder.getParent();
// that's not the selected element if possible get the selected element
if (parent instanceof MGenericStack) {
MUIElement selection = parent.getSelectedElement();
// if the selected element is the currently active part, the candidate is valid
if (selection == activePlaceholder || selection == currentlyActivePart) {
return candidate;
}
// if the selected element is the current candidate, the candidate is valid
if (selection == candidate || selection == placeholder) {
return candidate;
}
} else {
// not in a stack, just return the candidate then
return candidate;
}
}
}
return null;
}
use of org.eclipse.e4.ui.model.application.ui.MGenericStack in project eclipse.platform.ui by eclipse-platform.
the class LazyStackRenderer method postProcess.
@Override
public void postProcess(MUIElement element) {
if (!(element instanceof MPerspectiveStack) && (!(element instanceof MGenericStack<?>) || isMinimizedStack(element))) {
return;
}
@SuppressWarnings("unchecked") MGenericStack<MUIElement> stack = (MGenericStack<MUIElement>) element;
MUIElement selPart = stack.getSelectedElement();
if (selPart != null) {
showTab(selPart);
} else if (stack.getChildren().size() > 0) {
// Set the selection to the first renderable element
for (MUIElement kid : stack.getChildren()) {
if (kid.isToBeRendered() && kid.isVisible()) {
stack.setSelectedElement(kid);
break;
}
}
}
}
use of org.eclipse.e4.ui.model.application.ui.MGenericStack in project eclipse.platform.ui by eclipse-platform.
the class LazyStackRenderer method hideElementRecursive.
private void hideElementRecursive(MUIElement element) {
if (element == null) {
return;
}
// Recursively hide placeholder refs if reference is current
if (element instanceof MPlaceholder) {
MPlaceholder ph = (MPlaceholder) element;
if (ph.getRef() != null && ph.getRef().getCurSharedRef() == ph) {
hideElementRecursive(ph.getRef());
}
}
// Hide any floating windows
if (element instanceof MWindow) {
element.setVisible(false);
}
if (element instanceof MPart) {
MToolBar toolbar = ((MPart) element).getToolbar();
if (toolbar != null) {
toolbar.setVisible(false);
}
}
if (element instanceof MGenericStack<?>) {
// For stacks only the currently selected elements are being hidden
MGenericStack<?> container = (MGenericStack<?>) element;
MUIElement curSel = container.getSelectedElement();
hideElementRecursive(curSel);
} else if (element instanceof MElementContainer<?>) {
MElementContainer<?> container = (MElementContainer<?>) element;
for (MUIElement childElement : container.getChildren()) {
hideElementRecursive(childElement);
}
// OK, now process detached windows
if (element instanceof MWindow) {
for (MWindow w : ((MWindow) element).getWindows()) {
hideElementRecursive(w);
}
} else if (element instanceof MPerspective) {
for (MWindow w : ((MPerspective) element).getWindows()) {
hideElementRecursive(w);
}
}
}
}
use of org.eclipse.e4.ui.model.application.ui.MGenericStack in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method subscribeChildrenHandler.
@Inject
@Optional
private void subscribeChildrenHandler(@EventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN) Event event) {
Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(changedObj instanceof MElementContainer<?>)) {
return;
}
@SuppressWarnings("unchecked") MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj;
boolean isApplication = changedObj instanceof MApplication;
boolean menuChild = changedObj instanceof MMenu;
// If the parent isn't in the UI then who cares?
AbstractPartRenderer renderer = getRendererFor(changedElement);
if ((!isApplication && renderer == null) || menuChild) {
return;
}
if (UIEvents.isADD(event)) {
if (Policy.DEBUG_RENDERER) {
// $NON-NLS-1$
WorkbenchSWTActivator.trace(Policy.DEBUG_RENDERER_FLAG, "Child Added", null);
}
for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
MUIElement added = (MUIElement) o;
// OK, we have a new -visible- part we either have to create
// it or host it under the correct parent. Note that we
// explicitly do *not* render non-selected elements in
// stacks (to support lazy loading).
boolean isStack = changedObj instanceof MGenericStack<?>;
boolean hasWidget = added.getWidget() != null;
boolean isSelected = added == changedElement.getSelectedElement();
boolean renderIt = !isStack || hasWidget || isSelected;
if (renderIt) {
// NOTE: createGui will call 'childAdded' if successful
Object w = createGui(added);
if (w instanceof Control && !(w instanceof Shell)) {
final Control ctrl = (Control) w;
fixZOrder(added);
if (!ctrl.isDisposed()) {
ctrl.requestLayout();
}
}
} else if (renderer != null && added.isToBeRendered()) {
renderer.childRendered(changedElement, added);
}
// If the element being added is a placeholder, check to see if it's 'globally
// visible' and, if so, remove all other 'local' placeholders referencing the
// same element.
int newLocation = modelService.getElementLocation(added);
if (added instanceof MPlaceholder && (newLocation == EModelService.IN_SHARED_AREA || newLocation == EModelService.OUTSIDE_PERSPECTIVE)) {
MWindow topWin = modelService.getTopLevelWindowFor(added);
modelService.hideLocalPlaceholders(topWin, null);
}
}
} else if (UIEvents.isREMOVE(event)) {
if (Policy.DEBUG_RENDERER) {
// $NON-NLS-1$
WorkbenchSWTActivator.trace(Policy.DEBUG_RENDERER_FLAG, "Child Removed", null);
}
for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) {
MUIElement removed = (MUIElement) o;
// renderer is concerned
if (!removed.isToBeRendered()) {
continue;
}
if (removed.getWidget() instanceof Control) {
Control ctrl = (Control) removed.getWidget();
ctrl.setLayoutData(null);
ctrl.requestLayout();
}
// selected element
if (changedElement.getSelectedElement() == removed) {
changedElement.setSelectedElement(null);
}
if (renderer != null) {
renderer.hideChild(changedElement, removed);
}
}
}
}
use of org.eclipse.e4.ui.model.application.ui.MGenericStack in project eclipse.platform.ui by eclipse-platform.
the class TrimStack method updateTrimStackItems.
private void updateTrimStackItems() {
// Prevent exceptions on shutdown
if (trimStackTB == null || trimStackTB.isDisposed() || minimizedElement.getWidget() == null) {
return;
}
// Remove any current items except the 'restore' button
while (trimStackTB.getItemCount() > 1) {
trimStackTB.getItem(trimStackTB.getItemCount() - 1).dispose();
}
if (isEditorStack() && trimStackTB.getItemCount() == 1) {
ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
ti.setToolTipText(Messages.TrimStack_SharedAreaTooltip);
ti.setImage(getLayoutImage());
ti.addSelectionListener(toolItemSelectionListener);
} else if (minimizedElement instanceof MPlaceholder) {
MPlaceholder ph = (MPlaceholder) minimizedElement;
if (ph.getRef() instanceof MPart) {
MPart part = (MPart) ph.getRef();
ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
ti.setData(part);
ti.setImage(getImage(part));
ti.setToolTipText(getLabelText(part));
ti.addSelectionListener(toolItemSelectionListener);
}
} else if (minimizedElement instanceof MGenericStack<?>) {
// Handle *both* PartStacks and PerspectiveStacks here...
MGenericStack<?> theStack = (MGenericStack<?>) minimizedElement;
// check to see if this stack has any valid elements
boolean hasRenderedElements = false;
for (MUIElement stackElement : theStack.getChildren()) {
if (stackElement.isToBeRendered()) {
hasRenderedElements = true;
break;
}
}
if (hasRenderedElements) {
for (MUIElement stackElement : theStack.getChildren()) {
if (!stackElement.isToBeRendered()) {
continue;
}
MUILabel labelElement = getLabelElement(stackElement);
ToolItem newItem = new ToolItem(trimStackTB, SWT.CHECK);
newItem.setData(labelElement);
newItem.setImage(getImage(labelElement));
newItem.setToolTipText(getLabelText(labelElement));
newItem.addSelectionListener(toolItemSelectionListener);
}
} else if (theStack.getTags().contains(IPresentationEngine.NO_AUTO_COLLAPSE)) {
// OK to be empty and still minimized
ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
ti.setToolTipText(Messages.TrimStack_EmptyStackTooltip);
ti.setImage(getLayoutImage());
ti.addSelectionListener(toolItemSelectionListener);
} else {
// doesn't have any children that's showing, place it back in the presentation
restoreStack();
return;
}
}
trimStackTB.pack();
trimStackTB.requestLayout();
}
Aggregations