Java源码示例:org.eclipse.e4.ui.model.application.ui.MElementContainer
示例1
public static void execute(final GamaTree<String> tree) {
listDisplayViews();
// final List<IGamaView.Display> displays = WorkbenchHelper.getDisplayViews();
if (tree != null) {
DEBUG.LOG("Tree root = " + tree.getRoot().getChildren().get(0).getData() + " weight "
+ tree.getRoot().getChildren().get(0).getWeight());
if (tree.getRoot().getChildren().get(0).getWeight() == null) {
tree.getRoot().getChildren().get(0).setWeight(5000);
}
final List<MPlaceholder> holders = listDisplayViews();
final MPartStack displayStack = getDisplaysPlaceholder();
if (displayStack == null) { return; }
displayStack.setToBeRendered(true);
final MElementContainer<?> root = displayStack.getParent();
hideDisplays(displayStack, holders);
process(root, tree.getRoot().getChildren().get(0), holders);
showDisplays(root, holders);
} else {
decorateDisplays();
}
}
示例2
public static void hideDisplays(final MPartStack displayStack, final List<MPlaceholder> holders) {
final MElementContainer<MUIElement> parent = displayStack.getParent();
parent.setVisible(false);
holders.forEach((ph) -> {
ph.setVisible(false);
displayStack.getChildren().add(ph);
});
activateDisplays(holders, false);
for (final MUIElement element : new ArrayList<>(parent.getChildren())) {
if (element.getTransientData().containsKey(LAYOUT)) {
element.setVisible(false);
element.setToBeRendered(false);
parent.getChildren().remove(element);
}
}
}
示例3
public static void process(final MElementContainer uiRoot, final GamaNode<String> treeRoot,
final List<MPlaceholder> holders) {
final String data = treeRoot.getData();
final String weight = String.valueOf(treeRoot.getWeight());
// DEBUG.OUT("Processing " + data + " with weight " + weight);
final Boolean dir = !data.equals(HORIZONTAL) && !data.equals(VERTICAL) ? null : data.equals(HORIZONTAL);
final MPlaceholder holder = StreamEx.of(holders)
.findFirst(h -> h.getTransientData().get(DISPLAY_INDEX_KEY).equals(data)).orElse(null);
final MElementContainer container = create(uiRoot, weight, dir);
if (holder != null) {
if (container.equals(uiRoot)) {
holder.setContainerData(weight);
}
container.getChildren().add(holder);
} else {
for (final GamaNode<String> node : treeRoot.getChildren()) {
process(container, node, holders);
}
}
}
示例4
static MElementContainer create(final MElementContainer root, final String weight, final Boolean dir) {
if (dir == null) { // stacks cannot be stacked
if (root instanceof MPartStack && isPartOfLayout(root)) { return root; }
}
if (dir == null && (root instanceof MPartStack || !PerspectiveHelper.keepTabs())) { return root; }
final MElementContainer c = dir != null ? INSTANCE.createPartSashContainer() : INSTANCE.createPartStack();
c.getTransientData().put("Dynamic", true);
c.getTransientData().put(LAYOUT, true);
c.setContainerData(weight);
if (dir != null) {
((MPartSashContainer) c).setHorizontal(dir);
}
if (root != null) {
root.getChildren().add(c);
}
return c;
}
示例5
private void save(final MUIElement element, final List<MPlaceholder> holders, final GamaNode<String> parent,
final String weight) {
final String data = weight == null ? getWeight(element) : weight;
if (element instanceof MPlaceholder && holders.contains(element)) {
parent.addChild(valueOf(element.getTransientData().get(DISPLAY_INDEX_KEY)), parseInt(data));
} else if (element instanceof MElementContainer) {
final MElementContainer<?> container = (MElementContainer<?>) element;
final List<? extends MUIElement> children = getNonEmptyChildren(container, holders);
if (children.size() == 0) { return; }
if (children.size() == 1) {
save(children.get(0), holders, parent, data);
} else {
final GamaNode<String> node = parent.addChild(prefix(container), parseInt(data));
children.forEach(e -> save(e, holders, node, null));
}
}
}
示例6
void switchTo(MPart newPart) {
if (getOrderedStacks(apart).size() == 1) {
// case 1: 1 frame, split with miniPart
// convenience hack: change direction on uArg
splitIt(newPart, getDirection((isUniversalPresent()) ? !DISPLAY_HORIZONTAL : DISPLAY_HORIZONTAL));
} else {
// case 2: multiple stacks, move to adjacent stack
// get the starting stack
MElementContainer<MUIElement> stack = getParentStack(apart).getStack();
// get the topart's stack
MElementContainer<MUIElement> tstack = getParentStack(newPart).getStack();
stack = findNextStack(apart, stack, 1);
if (stack != null && stack != tstack) {
modelService.move(newPart, stack, 0);
}
}
if (displayOnly) {
// brings to top
partService.showPart(newPart, PartState.VISIBLE);
reactivate(apart);
} else {
// bug in Kepler forces us to activate the old before the new
reactivate(apart);
reactivate(newPart);
}
}
示例7
/**
* The parent of the apart is typically a PartStack, but it could be something under an MCompositePart, so look up
* @param apart the original selection
* @return the MPart and PartStack
*/
protected PartAndStack getParentStack(MPart apart) {
MPartSashContainerElement part = apart;
MElementContainer<MUIElement> stack = apart.getParent();
try {
while (!((MPartSashContainerElement)stack instanceof MPartStack)) {
if ((MPartSashContainerElement)stack instanceof MArea) {
// some unexpected structure
stack = null;
part = apart;
break;
} else {
part = (MPartSashContainerElement)stack;
stack = stack.getParent();
}
}
} catch (Exception e) {
// Bail on anything unexpected - will just make the command a noop
stack = null;
part = apart;
}
return new PartAndStack((MPart)part, stack);
}
示例8
/**
* Find the first element with which we should join
*
* @param dragStack the stack to join
* @return the target stack
*/
@SuppressWarnings("unchecked") // for safe cast to MElementContainer<MUIElement>
protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) {
MElementContainer<MUIElement> result = null;
if (dragStack != null) {
MElementContainer<MUIElement> psash = dragStack.getParent();
if ((Object)psash instanceof MPartSashContainer) {
List<MUIElement> children = psash.getChildren();
int size = children.size();
if (size > 1) {
int index = children.indexOf(dragStack)+1;
// use the next element, or previous if we're the last one
result = (MElementContainer<MUIElement>)children.get((index == size) ? index - 2 : index);
if (stackp) {
result = findTheStack(result);
}
}
}
}
return result;
}
示例9
/**
* @see com.mulgasoft.emacsplus.e4.commands.E4WindowCmd#getAdjacentElement(org.eclipse.e4.ui.model.application.ui.MElementContainer, boolean, org.eclipse.e4.ui.model.application.ui.basic.MPart)
*/
protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) {
MElementContainer<MUIElement> result = null;
if (dragStack != null) {
MElementContainer<MUIElement> psash = dragStack.getParent();
MElementContainer<MUIElement> top = getTopElement(psash);
if ((Object)top instanceof MTrimmedWindow) {
// if we contain splits, remove them first
if (top != psash) {
super.joinAll(part);
}
Collection<MPart> parts = getParts(application.getChildren().get(0), EModelService.IN_SHARED_AREA);
for (MPart p : parts) {
List<MElementContainer<MUIElement>> all = getOrderedStacks(p);
// if it has a PartStack, it sh/c/ould be an editor stack
if (!all.isEmpty()) {
result = all.get(0);
break;
};
};
}
}
return result;
}
示例10
/**
* Merge the stack containing the selected part into its neighbor and return the
* element to activate. This will be the originating buffer on split-self or the
* active element in the other stack if not.
*
* @param apart
* @return the element to select
*/
MPart joinOne(MPart apart) {
// We're going to end up with 1, so avoid the overhead of futzing with the stacks
if (isSplitSelf() && getOrderedStacks(apart).size() < 3) {
this.joinAll(apart);
return apart;
} else {
PartAndStack ps = getParentStack(apart);
MElementContainer<MUIElement> pstack = ps.getStack();
MPart part = ps.getPart();
MElementContainer<MUIElement> adjacent = getAdjacentElement(pstack, part, true);
MUIElement otherPart = getSelected(adjacent);
// deduplicate editors across these two stacks
closeOthers(pstack, adjacent);
if (pstack == null || join2Stacks(pstack, adjacent, part) == null) {
// Invalid state
Beeper.beep();
}
return (otherPart instanceof MPart) ? (MPart)otherPart : apart;
}
}
示例11
/**
* Get all the IEditorReferences in a given part stack
*
* @param stack
* @return the collection of IEditorReferences
*/
private Collection<IEditorReference> getStackEditors(MElementContainer<MUIElement> stack) {
Collection<IEditorReference> editors = new ArrayList<IEditorReference>();
for (MUIElement child : stack.getChildren()) {
if (child instanceof MPart) {
// TODO: There must be a better way of getting the editor out of e4, but I can't find it
Object cEditor = ((MPart) child).getObject();
if (cEditor != null) {
try {
// avoid discouraged access of org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor
// which is expected cEditor's type in e4
Method method = cEditor.getClass().getMethod(GET_REF);
if (method != null) {
IEditorReference ie = (IEditorReference)method.invoke(cEditor);
editors.add(ie);
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | ClassCastException e) {
}
}
}
}
return editors;
}
示例12
@Execute
protected void doOtherWindow(@Active MPart apart, @Named(E4CmdHandler.CMD_CTX_KEY)String cmd, @Active EmacsPlusCmdHandler handler) {
PartAndStack ps = getParentStack(apart);
MElementContainer<MUIElement> otherStack = getAdjacentElement(ps.getStack(), ps.getPart(), true);
MPart other = (MPart)otherStack.getSelectedElement();
// TODO An egregious hack that may break at any time
// Is there a defined way of getting the IEditorPart from an MPart?
if (other.getObject() instanceof CompatibilityEditor) {
IEditorPart editor = ((CompatibilityEditor) other.getObject()).getEditor();
try {
reactivate(other);
if (handler.isUniversalPresent()) {
EmacsPlusUtils.executeCommand(cmd, handler.getUniversalCount(), null, editor);
} else {
EmacsPlusUtils.executeCommand(cmd, null, editor);
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
reactivate(apart);
}
}
}
示例13
/**
* well, this goes to the renderer.
*
* @param mgr
*/
public void addMenuContributions(IMenuManager mgr) {
IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
if (obj instanceof MenuManagerRenderer) {
MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
renderer.reconcileManagerToModel(menu, menuModel);
renderer.processContributions(menuModel, menuModel.getElementId(), false, true);
// double cast because we're bad people
renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel));
List<MMenuElement> toRemove = new ArrayList<>();
for (MMenuElement e : menuModel.getChildren()) {
if (!(e instanceof MMenuSeparator || INCLUDES.contains(e.getElementId())
|| e.getElementId() == null)) {
if (e.getElementId() != null && !e.getElementId().startsWith("org.bonitasoft.studio.")) {
toRemove.add(e);
e.setVisible(false);
}
}
}
menuModel.getChildren().removeAll(toRemove);
}
}
示例14
public static void showDisplays(final MElementContainer<?> root, final List<MPlaceholder> holders) {
root.setVisible(true);
decorateDisplays();
holders.forEach((ph) -> {
ph.setVisible(true);
ph.setToBeRendered(true);
});
activateDisplays(holders, true);
}
示例15
@Execute
public void execute(EModelService modelService, MWindow window, EPartService partService) {
// get active perpective and find stored snippet of this perspective
MPerspective activePerspective = modelService.getActivePerspective(window);
MUIElement perspectiveSnippet = modelService.cloneSnippet(window, activePerspective.getElementId(), window);
// remove existing active perspective
MElementContainer<MUIElement> parent = activePerspective.getParent();
modelService.removePerspectiveModel(activePerspective, window);
// add stored perspective snippet and switch to it
parent.getChildren().add(perspectiveSnippet);
partService.switchPerspective((MPerspective) perspectiveSnippet);
}
示例16
@Execute
public Object execute(@Active MPart apart, @Named(E4CmdHandler.CMD_CTX_KEY)Col stype, @Active EmacsPlusCmdHandler handler) {
PartAndStack ps = getParentStack(apart);
MElementContainer<MUIElement> stack = ps.getStack();
MElementContainer<MUIElement> next = getAdjacentElement(stack, ps.getPart(), false);
int count = handler.getUniversalCount();
// if we have an adjacent part, we're in a sash
if (next != null) {
switch (stype) {
case SHRINK:
adjustContainerData((MUIElement)stack, (MUIElement)next, count, getTotalSize(apart));
break;
case ENLARGE:
adjustContainerData((MUIElement)next, (MUIElement)stack, count, getTotalSize(apart));
break;
case BALANCE:
balancePartSash(stack);
break;
}
// For some reason, in recent eclipses, we have to request the layout manually
Object widget = stack.getWidget();
// Double check before grabbing the parent composite for looping
if (widget instanceof CTabFolder) {
// this is apparently the recommended way of getting these to redraw properly
for (Control c : ((Composite)widget).getParent().getChildren()) {
c.requestLayout();
}
}
}
return null;
}
示例17
/**
* Get the ordered list of stacks
* @param apart
* @return a list of MElementContainer<MUIElement> representing all the PartStacks
*/
protected List<MElementContainer<MUIElement>> getOrderedStacks(MPart apart) {
List<MElementContainer<MUIElement>> result = new ArrayList<MElementContainer<MUIElement>>();
MElementContainer<MUIElement> parent = getTopElement(apart.getParent());
if (parent != null) {
result = getStacks(result, parent);
}
return result;
}
示例18
private List<MElementContainer<MUIElement>> getStacks(List<MElementContainer<MUIElement>> result, MElementContainer<MUIElement> container) {
for (MUIElement child : container.getChildren()) {
@SuppressWarnings("unchecked") // We type check all the way down
MElementContainer<MUIElement> c = (MElementContainer<MUIElement>)child;
if (child instanceof MPartStack) {
result.add(c);
} else {
getStacks(result,c);
}
}
return result;
}
示例19
/**
* If parent is a sash, keep looking until we find a PartStack
*
* @param parent a sash of PartStack
* @return the first PartStack we find
*/
@SuppressWarnings("unchecked") // for safe cast to MElementContainer<MUIElement>
private MElementContainer<MUIElement> findTheStack(MElementContainer<MUIElement> parent) {
MElementContainer<MUIElement> result = parent;
if ((MPartSashContainerElement)parent instanceof MPartSashContainer) {
List<MUIElement> children = parent.getChildren();
result = findTheStack((MElementContainer<MUIElement>)children.get(0));
}
return result;
}
示例20
/**
* Rotate through stacks by <count> elements
*
* @param part the source part
* @param stack the source stack
* @param count the number to rotate by
* @return the destination stack
*/
protected MElementContainer<MUIElement> findNextStack(MPart part, MElementContainer<MUIElement> stack, int count) {
MElementContainer<MUIElement> nstack = null;
List<MElementContainer<MUIElement>> stacks = getOrderedStacks(part);
int size = stacks.size();
if (size > 1) {
int index = stacks.indexOf(stack) + (count % size);
nstack = (index < 0) ? stacks.get(size + index) : (index < size) ? stacks.get(index) : stacks.get(index - size);
}
return nstack;
}
示例21
/**
* @param ele start from here
* @return the most distant parent for the editor area
*/
protected MElementContainer<MUIElement> getTopElement(MElementContainer<MUIElement> ele) {
MElementContainer<MUIElement> parent = ele;
// get the outer container
if (parent != null) {
while (!((Object)parent instanceof MArea) && parent.getParent() != null) {
parent = parent.getParent();
}
}
return parent;
}
示例22
private int sizeIt(MUIElement ele) {
int result = 0;
if (ele.getContainerData() != null) {
result = getIntData(ele);
} else if (ele instanceof MElementContainer) {
@SuppressWarnings("unchecked") //checked
List<MUIElement> mlist = ((MElementContainer<MUIElement>)ele).getChildren();
for (MUIElement mui : mlist) {
result += sizeIt(mui);
}
}
return result;
}
示例23
@SuppressWarnings("unchecked") // manually checked
MUIElement getSelected(MUIElement ele) {
MUIElement sel = ele;
while (sel instanceof MElementContainer) {
sel = ((MElementContainer<MUIElement>)sel).getSelectedElement();
}
// on occasion the above returns null which is bizarre, so try skipping the first level
if (sel == null && ele instanceof MElementContainer) {
List<MUIElement> c = ((MElementContainer<MUIElement>)ele).getChildren();
if (c.size() == 1 && c.get(0) instanceof MPartStack) {
sel = ((MElementContainer<MUIElement>)c.get(0)).getSelectedElement();
}
}
return sel;
}
示例24
protected void splitIt(MPart apart, int location) {
PartAndStack ps = getParentStack(apart);
MElementContainer<MUIElement> pstack = ps.getStack();
if (pstack.getChildren().size() > 1) {
MPart newpart = ps.getPart();
MPartStack nstack = getStack(newpart, pstack);
// Let the model service take care of the rest of the split
modelService.insert(nstack, (MPartSashContainerElement)pstack, location, ratio);
}
}
示例25
/**
* Wrap the editor (MPart) up in a new PartStack
* @param apart
* @return the wrapped MPart
*/
private MPartStack getStack(MPart apart, MElementContainer<MUIElement> parent) {
MPartStack result = MBasicFactory.INSTANCE.createPartStack();
MStackElement stackElement = (MStackElement) apart;
parent.getChildren().remove(apart);
result.getChildren().add(stackElement);
result.setSelectedElement(stackElement);
return result;
}
示例26
@Override
void joinAll(MPart apart) {
joined = true;
List<MTrimmedWindow> frames = getDetachedFrames();
MElementContainer<MUIElement> last = getTopElement((MElementContainer<MUIElement>) apart.getParent());
for (MTrimmedWindow mt : frames) {
if (!mt.equals(last)) {
joinOne(mt);
}
}
// only join apart if its top element is a frame
if ((Object)last instanceof MTrimmedWindow) {
super.joinOne(apart);
}
}
示例27
/**
* Merge all stacks into one
*
* @param apart - the selected MPart
*/
void joinAll(MPart apart) {
try {
// deduplicate editors across all stacks
IDeduplication.closeAllDuplicates(EmacsPlusUtils.getWorkbenchPage());
} catch (PartInitException e) {
// Ignore
}
List<MElementContainer<MUIElement>> stacks = getOrderedStacks(apart);
if (stacks.size() > 1) {
PartAndStack ps = getParentStack(apart);
MElementContainer<MUIElement> pstack = ps.getStack();
MPart part = ps.getPart();
// check for unexpected result - who knows what Eclipse might do
if (pstack != null) {
MElementContainer<MUIElement> dropStack = stacks.get(0);
for (int i = 1; i < stacks.size(); i++) {
MElementContainer<MUIElement> stack = stacks.get(i);
if (stack == pstack) {
continue;
}
join2Stacks(stacks.get(i), dropStack, null);
}
// lastly, join in the selected stack
if (pstack != dropStack) {
join2Stacks(pstack, dropStack, part);
}
} else {
Beeper.beep();
}
}
}
示例28
/**
* Close any duplicate editors in the supplied part stacks
*
* @param stack1
* @param stack2
* @return true if any duplicates were closed
*/
boolean closeOthers(MElementContainer<MUIElement> stack1, MElementContainer<MUIElement> stack2) {
boolean result = false;
Collection<IEditorReference> editors = getStackEditors(stack1);
editors.addAll(getStackEditors(stack2));
try {
result = IDeduplication.closeDuplicates(EmacsPlusUtils.getWorkbenchPage(), editors.toArray(new IEditorReference[editors.size()]));
} catch (PartInitException e) {
// Ignore
}
return result;
}
示例29
/**
* Given 2 partStacks, move children of pstack into dropStack
* @param pstack - source stack
* @param dropStack - destination stack
* @param apart - the initiating part
* @return the enhanced dropStack
*/
protected MElementContainer<MUIElement> join2Stacks(MElementContainer<MUIElement> pstack, MElementContainer<MUIElement> dropStack, MPart apart) {
if (dropStack != null && ((MPartSashContainerElement)dropStack) instanceof MPartStack) {
List<MUIElement> eles = pstack.getChildren();
boolean hasPart = apart != null;
int offset = 1;
List<MUIElement> drops = dropStack.getChildren();
while (eles.size() > (hasPart ? 1 : 0)) {
MUIElement ele = eles.get(eles.size() - offset);
if (hasPart && ele == apart) {
offset++;
continue;
}
eles.remove(ele);
if (hasPart) {
drops.add(0,ele);
} else {
drops.add(ele);
}
}
if (hasPart) {
// Move the selected element to the leftmost position
eles.remove(apart);
drops.add(0,apart);
dropStack.setSelectedElement(apart);
}
checkSizeData(pstack,dropStack);
}
return dropStack;
}
示例30
/**
* Check if containerData size needs updating.
* This should be handled by the Eclipse framework, but apparently not...
* @param pstack - source stack
* @param dropStack - destination stack
*/
protected void checkSizeData(MElementContainer<MUIElement> pstack, MElementContainer<MUIElement> dropStack) {
if (pstack.getParent().getContainerData() == null) {
int s1 = getIntData(pstack);;
if (dropStack.getParent().getContainerData() == null) {
// stacks are vertically side by side, add their sizes together
dropStack.setContainerData(String.valueOf(s1 + getIntData(dropStack)));
} else {
// source is vertical & destination is in a horizontal containing PartSash
dropStack.getParent().setContainerData(String.valueOf(s1 + getIntData(dropStack.getParent())));
}
}
}