private static String getContextName(MApplicationElement element) { StringBuilder builder = new StringBuilder(element.getClass().getSimpleName()); String elementId = element.getElementId(); if (elementId != null && elementId.length() != 0) { builder.append(" (").append(elementId).append(") "); //$NON-NLS-1$ //$NON-NLS-2$ } builder.append("Context"); //$NON-NLS-1$ return builder.toString(); }
private void addMenu(MApplicationElement model, MMenu menu, IEclipseContext ctx) { ArrayList<MMenu> menus = (ArrayList<MMenu>) model.getTransientData().get(POPULATED_MENUS); if (menus == null) { menus = new ArrayList<>(); model.getTransientData().put(POPULATED_MENUS, menus); } if (menus.contains(menu)) { return; } menus.add(menu); menu.getTransientData().put(ModelUtils.CONTAINING_PARENT, model); ((Notifier) menu).eAdapters().add(ctx.get(UIEventPublisher.class)); }
private void createIdentifierTracker(MApplicationElement item) { if (item.getElementId() != null && item.getElementId().length() > 0) { String id = namespaceIdentifier + "/" + item.getElementId(); //$NON-NLS-1$ item.getPersistedState().put(MenuManagerRenderer.VISIBILITY_IDENTIFIER, id); final IIdentifier identifier = activityManager.getIdentifier(id); if (identifier != null) { application.getContext().set(identifier.getId(), identifier.isEnabled()); identifier.addIdentifierListener(idUpdater); } } }
@Override public boolean select(MApplicationElement element) { if (id != null && !id.equals(element.getElementId())) { return false; } if (clazz != null && !(clazz.isInstance(element))) { return false; } if (tagsToMatch != null) { List<String> elementTags = element.getTags(); for (String tag : tagsToMatch) { if (!elementTags.contains(tag)) { return false; } } } return true; } }
Object storedNewValue = appElement.getTransientData().get(key); Object notificationNewValue = notification.getNewValue(); Object storedNewValue = appElement.getPersistedState().get(key); Object notificationNewValue = notification.getNewValue();
@Override public Object compute(IEclipseContext context) { MApplicationElement mApplicationElement = context.get(MApplicationElement.class); if (mApplicationElement == null) { return null; } else { return new MementoImpl(mApplicationElement.getPersistedState()); } }
@Override public <T extends MApplicationElement> @NonNull T createModelElement(@NonNull Class<@NonNull T> clazz, @NonNull Supplier<@NonNull String> contributor, Function<@NonNull T, @NonNull T> processor) { T element = this.modelService.createModelElement(clazz); element.setContributorURI("platform:/plugin/" + contributor); //$NON-NLS-1$ element = processor.apply(element); return element; }
/** * Returns localized string for the key from the application element using * translation service from the context. * <p> * This method will return the key itself if the context is <code>null</code> * or there is no translation service registered in the given context. * </p> * * @param key * the key * @param element * the model element * @param context * the context * @return localized key */ public static String getLocalized(String key, MApplicationElement element, IEclipseContext context) { if (key == null || context == null) return key; TranslationService translation = context.get(TranslationService.class); if (translation == null) return key; return translation.translate(key, element.getContributorURI()); }
/** * Initialize the context * * @param eo * the object the context should be populated with * @param context * the context */ @SuppressWarnings("static-method") protected void initContext(@NonNull EObject eo, @NonNull IEclipseContext context) { for (EAttribute e : eo.eClass().getEAllAttributes()) { context.set(e.getName(), eo.eGet(e)); } if (eo instanceof MApplicationElement) { for (Entry<String, String> e : ((MApplicationElement) eo).getPersistedState().entrySet()) { context.set(UIEvents.ApplicationElement.PERSISTEDSTATE + "_" //$NON-NLS-1$ + e.getKey(), e.getValue()); } } // // Localized Label/Tooltip treatment // if (eo instanceof MUILabel) { // MUILabel l = (MUILabel) eo; // context.set(ATTRIBUTE_localizedLabel, l.getLocalizedLabel()); // context.set(ATTRIBUTE_localizedTooltip, l.getLocalizedTooltip()); // } }
private Resource loadResource(URI uri) { Resource resource; try { resource = getResource(uri); } catch (Exception e) { // TODO We could use diagnostics for better analyzing the error logger.error(e, "Unable to load resource " + uri.toString()); //$NON-NLS-1$ return null; } // TODO once we switch from deltas, we only need this once on the default model? String contributorURI = URIHelper.EMFtoPlatform(uri); if (contributorURI != null) { TreeIterator<EObject> it = EcoreUtil.getAllContents(resource.getContents()); while (it.hasNext()) { EObject o = it.next(); if (o instanceof MApplicationElement) { ((MApplicationElement) o).setContributorURI(contributorURI); } } } return resource; }
/** * Returns localized string for the key from the application element using * translation service from the context. * <p> * This method will return the key itself if the context is <code>null</code> * or there is no translation service registered in the given context. * </p> * * @param key * the key * @param element * the model element * @param context * the context * @return localized key */ public static String getLocalized(String key, MApplicationElement element, IEclipseContext context) { if (key == null || context == null) return key; TranslationService translation = context.get(TranslationService.class); if (translation == null) return key; return translation.translate(key, element.getContributorURI()); }
@Override public Color getForeground(Object element) { if (element instanceof MApplicationElement) { String elementId = ((MApplicationElement) element).getElementId(); MPerspective activePerspective = modelService.getActivePerspective(window); if(partService.isPartOrPlaceholderInPerspective(elementId, activePerspective)){ return dimmedForeground; } } return null; } }
private void addToolbar(MApplicationElement model, MToolBar tb, IEclipseContext ctx) { ArrayList<MToolBar> toolbars = (ArrayList<MToolBar>) model.getTransientData().get( POPULATED_TOOL_BARS); if (toolbars == null) { toolbars = new ArrayList<>(); model.getTransientData().put(POPULATED_TOOL_BARS, toolbars); } if (toolbars.contains(tb)) { return; } toolbars.add(tb); tb.getTransientData().put(ModelUtils.CONTAINING_PARENT, model); ((Notifier) tb).eAdapters().add(ctx.get(UIEventPublisher.class)); }
@Override public boolean openEditor(String uri) { List<MPart> list = modelService.findElements(application, MPart.class, EModelService.ANYWHERE, (p) -> { return uri.equals(p.getPersistedState().get(Constants.DOCUMENT_URL)); });
el.setContributorURI(contributorURI); r = (E4XMIResource) eObj.eResource(); if (contributorURI != null && (eObj instanceof MApplicationElement)) ((MApplicationElement) eObj).setContributorURI(contributorURI); applicationResource.setID(eObj, r.getInternalId(eObj));
public static MApplicationElement findElementById(MApplicationElement element, String id) { if (id == null || id.length() == 0) { return null; } // is it me? if (id.equals(element.getElementId())) { return element; } // Recurse if this is a container EList<EObject> elements = ((EObject) element).eContents(); for (EObject childElement : elements) { if (!(childElement instanceof MApplicationElement)) { continue; } MApplicationElement result = findElementById((MApplicationElement) childElement, id); if (result != null) { return result; } } return null; }
static MApplicationElement getParent(MApplicationElement element) { if ( (element instanceof MUIElement) && ((MUIElement)element).getCurSharedRef() != null) { return ((MUIElement)element).getCurSharedRef().getParent(); } else if (element != null && element.getTransientData() != null && element.getTransientData().get(CONTAINING_PARENT) instanceof MApplicationElement) { return (MApplicationElement) element.getTransientData().get(CONTAINING_PARENT); } else if (element instanceof EObject) { EObject eContainer = ((EObject) element).eContainer(); if (eContainer instanceof MApplicationElement) { return (MApplicationElement) eContainer; } } return null; }
public static MApplicationElement findElementById(MApplicationElement element, String id) { if (id == null || id.length() == 0) { return null; } // is it me? if (id.equals(element.getElementId())) { return element; } // Recurse if this is a container EList<EObject> elements = ((EObject) element).eContents(); for (EObject childElement : elements) { if (!(childElement instanceof MApplicationElement)) { continue; } MApplicationElement result = findElementById((MApplicationElement) childElement, id); if (result != null) { return result; } } return null; }
static MApplicationElement getParent(MApplicationElement element) { if ( (element instanceof MUIElement) && ((MUIElement)element).getCurSharedRef() != null) { return ((MUIElement)element).getCurSharedRef().getParent(); } else if (element.getTransientData().get(CONTAINING_PARENT) instanceof MApplicationElement) { return (MApplicationElement) element.getTransientData().get(CONTAINING_PARENT); } else if (element instanceof EObject) { EObject eContainer = ((EObject) element).eContainer(); if (eContainer instanceof MApplicationElement) { return (MApplicationElement) eContainer; } } return null; }
elements.toArray(tmp); for(MApplicationElement element : tmp) { String elementID = element.getElementId(); boolean found = false; if ((elementID != null) && (elementID.length() != 0)) { if (!elementID.equals(existingEObject.getElementId())) { continue;