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); } } }
/** Default constructor. */ public PageflowStructureViewerLabelProvider() { adapterProvider = new AdapterFactoryLabelProvider(AdapterUtils.getAdapterFactory()); if (adapterProvider.getAdapterFactory() instanceof ComposedAdapterFactory) { ComposedAdapterFactory cFactory = (ComposedAdapterFactory) adapterProvider.getAdapterFactory(); cFactory.insertAdapterFactory(new PageflowCompareItemProviderAdapterFactory()); } }
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); }
/** @generated */ public String getText(Object element) { if (element instanceof SysmlDomainNavigatorItem) { return myAdapterFactoryLabelProvider.getText( ((SysmlDomainNavigatorItem) element).getEObject()); } return null; }
/** * 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; }
/** * Returns the name of the given {@link IFile}, delegates to {@link * AdapterFactoryLabelProvider#getText(Object)} if not an {@link IFile}. * * @param object Object we seek the name for. * @return The name of the given object. * @see AdapterFactoryLabelProvider#getText(Object) */ public String getText(Object object) { String text = null; if (object instanceof AbstractDiffExtension) { text = ((AbstractDiffExtension) object).getText(); } else { if (object instanceof IFile) { text = ((IFile) object).getName(); } else if (object instanceof Resource) { text = ((Resource) object).getURI().lastSegment(); } else { text = adapterProvider.getText(object); } } return text; }
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); }
@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(); } }
@Override public void notifyChanged(final Notification notification) { if (fViewer != null && fViewer.getControl() != null && !fViewer.getControl().isDisposed() && notification instanceof IViewerNotification) { final IViewerNotification viewerNotification = (IViewerNotification) notification; if (viewerNotification.isLabelUpdate()) { if (fViewerRefresh == null) { fViewerRefresh = new AdapterFactoryContentProvider.ViewerRefresh(fViewer); } if (fViewerRefresh.addNotification(viewerNotification)) { fViewer.getControl().getDisplay().asyncExec(fViewerRefresh); } } } super.notifyChanged(notification); }
/** @generated */ public void removeListener(ILabelProviderListener listener) { myAdapterFactoryLabelProvider.removeListener(listener); }
/** @generated */ public boolean isLabelProperty(Object element, String property) { return myAdapterFactoryLabelProvider.isLabelProperty(element, property); }
/** @generated */ public void dispose() { myAdapterFactoryLabelProvider.dispose(); }
/** @generated */ public void addListener(ILabelProviderListener listener) { myAdapterFactoryLabelProvider.addListener(listener); }