public void buildTree() { for (int i = 0; i < oldExpressions.size(); i++) { final Expression oldExpression = oldExpressions.get(i); CompareScript left = new CompareScript(oldExpression.getName(), oldExpression); left.setElement(oldExpression); left.setImage(adapterFactoryLabelProvider.getImage(oldExpression)); final Expression newExpression = newExpressions.get(i); final CompareScript right = new CompareScript(newExpression.getName(), newExpression); right.setElement(newExpression); right.addContentChangeListener( new IContentChangeListener() { @Override public void contentChanged(IContentChangeNotifier compareScript) { if (compareScript instanceof CompareScript) { setDirty(true); if (getViewer() == null || getViewer().getControl().isDisposed()) return; getViewer().refresh(true); } } }); right.setImage(adapterFactoryLabelProvider.getImage(newExpression)); DiffNode leaf = new DiffNode(null, Differencer.CHANGE, null, left, right); final DiffNode poolNode = buildPathNodes(oldExpression.eContainer(), leaf); if (((CompareScript) poolNode.getAncestor()).getElement() instanceof Pool && root.getChildren().length == 0) { root.add(poolNode); } } }
/** @generated */ public Image getImage(Object element) { if (element instanceof SysmlDomainNavigatorItem) { return myAdapterFactoryLabelProvider.getImage( ((SysmlDomainNavigatorItem) element).getEObject()); } return null; }
protected Image getImage(EObject element) { if (!Platform.isRunning()) { return null; } ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory()); adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory()); adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory); return labelProvider.getImage(element); }
/** * Returns the platform icon for a given {@link IFile}. If not an {@link IFile}, delegates to the * {@link AdapterFactoryLabelProvider} to get the {@link Image}. * * @param object Object to get the {@link Image} for. * @return The platform icon for the given object. * @see AdapterFactoryLabelProvider#getImage(Object) */ public Image getImage(Object object) { Image image = null; if (object instanceof AbstractDiffExtension) { image = (Image) ((AbstractDiffExtension) object).getImage(); } if (object instanceof IFile) { image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE); } else { if (image == null) { image = adapterProvider.getImage(object); } } return image; }
@Test public void testGetImageObject() { AdapterFactory adapterFactoryImpl = new ProjectItemProviderAdapterFactory(); LayerItemProvider itemProvider = new LayerItemProvider(adapterFactoryImpl); AdapterFactoryLabelProvider fac = new AdapterFactoryLabelProvider(adapterFactoryImpl); Image image = null; Image image2 = null; try { layer.eAdapters().add(itemProvider); image = (Image) fac.getImage(layer); assertNotNull(image); image2 = (Image) fac.getImage(layer); assertSame(image, image2); layer .getProperties() .put(LayerItemProvider.GENERATED_ICON, Glyph.geometry(Color.RED, Color.BLACK)); image2 = (Image) fac.getImage(layer); assertNotSame(image, image2); layer .getProperties() .put(LayerItemProvider.GENERATED_ICON, Glyph.geometry(Color.GREEN, Color.BLACK)); image = (Image) fac.getImage(layer); assertNotSame(image, image2); layer.setIcon(Glyph.geometry(Color.GREEN, Color.RED)); image2 = (Image) fac.getImage(layer); assertNotSame(image, image2); layer .getProperties() .put(LayerItemProvider.GENERATED_ICON, Glyph.geometry(Color.GREEN, Color.BLUE)); image = (Image) fac.getImage(layer); assertSame(image, image2); } finally { fac.dispose(); itemProvider.dispose(); } }
private DiffNode buildPathNodes(EObject container, DiffNode node) { DiffNode parentNode = new DiffNode(Differencer.NO_CHANGE); node.setParent(parentNode); parentNode.add(node); CompareScript ancestor = null; String name = adapterFactoryLabelProvider.getText(container); Expression expr = ExpressionHelper.createConstantExpression(name, String.class.getName()); expr.setName(name); ancestor = new CompareScript(expr.getName(), expr); ancestor.setElement(container); ancestor.setImage(adapterFactoryLabelProvider.getImage(container)); parentNode.setAncestor(ancestor); if (insertParentNode(parentNode)) { return parentNode; } if (container instanceof Pool) { return parentNode; } if (container instanceof ConnectorParameter) { return buildPathNodes(container.eContainer().eContainer(), parentNode); } return buildPathNodes(container.eContainer(), parentNode); }