Example usage for org.eclipse.jface.viewers IDecoration addPrefix

List of usage examples for org.eclipse.jface.viewers IDecoration addPrefix

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IDecoration addPrefix.

Prototype

void addPrefix(String prefix);

Source Link

Document

Adds a prefix to the element's label.

Usage

From source file:org.eclipsetrader.ui.internal.trading.WatchlistAlertDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof IAdaptable) {
        element = ((IAdaptable) element).getAdapter(ISecurity.class);
    }//from  w w  w . j ava  2  s. c  o  m

    if (element == null || !(element instanceof ISecurity)) {
        return;
    }

    decoration.addPrefix("*"); //$NON-NLS-1$
    if (alertService.hasTriggeredAlerts((ISecurity) element)) {
        if (foreground == null) {
            foreground = new Color(Display.getDefault(), 255, 0, 0);
        }
        decoration.setBackgroundColor(foreground);
    }
}

From source file:org.openhealthtools.mdht.uml.ui.navigator.internal.StereotypeLightweightDecorator.java

License:Open Source License

public void decorate(Object object, IDecoration decoration) {
    Element element = null;/*from w w  w. j av a  2  s  .  c  o  m*/
    if (object instanceof Element) {
        element = (Element) object;
    } else if (object instanceof IAdaptable) {
        element = (Element) ((IAdaptable) object).getAdapter(Element.class);
    }
    if (element != null && !element.getAppliedStereotypes().isEmpty()) {
        StringBuilder decorator = new StringBuilder();
        for (Iterator iterator = element.getAppliedStereotypes().iterator(); iterator.hasNext();) {
            Stereotype stereotype = (Stereotype) iterator.next();
            EAnnotation extensions = stereotype.getEAnnotation("uml2.extensions");
            boolean suppressed = extensions != null && extensions.getDetails() != null
                    && "true".equals(extensions.getDetails().get("suppressed"));
            if (!suppressed) {
                if (decorator.length() == 0) {
                    decorator.append("<<");
                } else {
                    decorator.append(", ");
                }
                // keyword gets localized name, or lowerCamelCase of Stereotype name
                decorator.append(stereotype.getKeyword());
            }
        }
        if (decorator.length() > 0) {
            decorator.append(">> ");
            decoration.addPrefix(decorator.toString());
        }
    }
}

From source file:org.polymap.core.data.feature.buffer.LayerBufferDecorator.java

License:Open Source License

public void decorate(Object elm, IDecoration decoration) {
    boolean incoming = false;
    boolean outgoing = false;

    // check removed; handled by EntityModificationDecorator
    try {//from w  ww . j  ava2s  .c o m
        ((Entity) elm).id();
    } catch (NoSuchEntityException e) {
        return;
    }

    try {
        // ILayer
        if (elm instanceof ILayer) {
            ILayer layer = (ILayer) elm;
            outgoing = modified.containsKey(layer.id());

            //                EntityHandle layerHandle = FeatureStateTracker.layerHandle( layer );
            //                boolean incoming = EntityStateTracker.instance().isConflicting( 
            //                        layerHandle, layerBuffer.getLayerTimestamp() );
            decorated.put(layer.id(), layer);
        }
        // IMap
        else if (elm instanceof IMap) {
            IMap map = (IMap) elm;
            final AtomicBoolean outgo = new AtomicBoolean(outgoing);
            map.visit(new LayerVisitor() {
                public boolean visit(ILayer layer) {
                    outgo.set(modified.containsKey(layer.id()));
                    return !outgo.get();
                }
            });
            outgoing = outgo.get();
            decorated.put(map.id(), map);
        }

        if (outgoing && incoming) {
            decoration.addPrefix("# ");
        } else if (incoming) {
            decoration.addPrefix("< ");
        } else if (outgoing) {
            ImageDescriptor ovr = DataPlugin.getDefault().imageDescriptor(OUTGOING);
            decoration.addOverlay(ovr, BOTTOM_RIGHT);
            //decoration.addSuffix( "*" );
        }
    } catch (Exception e) {
        log.warn("", e);
        // XXX add question mark overlay
    }

}

From source file:org.spearce.egit.ui.internal.decorators.GitResourceDecorator.java

License:Open Source License

public void decorate(final Object element, final IDecoration decoration) {
    final IResource rsrc = toIResource(element);
    if (rsrc == null)
        return;//  w  w w  .j a  v a 2s. c om

    // If the workspace has not been refreshed properly a resource might
    // not actually exist, so we ignore these and do not decorate them
    if (!rsrc.exists() && !rsrc.isPhantom()) {
        Activator.trace("Tried to decorate non-existent resource " + rsrc);
        return;
    }

    RepositoryMapping mapped = RepositoryMapping.getMapping(rsrc);

    // TODO: How do I see a renamed resource?
    // TODO: Even trickier: when a path change from being blob to tree?
    try {
        if (mapped != null) {
            Repository repository = mapped.getRepository();
            GitIndex index = repository.getIndex();
            String repoRelativePath = mapped.getRepoRelativePath(rsrc);
            Tree headTree = repository.mapTree("HEAD");
            TreeEntry blob = headTree != null ? headTree.findBlobMember(repoRelativePath) : null;
            Entry entry = index.getEntry(repoRelativePath);
            if (entry == null) {
                if (blob == null) {
                    if (rsrc instanceof IContainer) {
                        Integer df = (Integer) rsrc.getSessionProperty(GITFOLDERDIRTYSTATEPROPERTY);
                        Boolean f = df == null ? isDirty(rsrc) : Boolean.valueOf(df.intValue() == CHANGED);
                        if (f != null) {
                            if (f.booleanValue()) {
                                decoration.addPrefix(">"); // Have not
                                // seen
                                orState(rsrc, CHANGED);
                            } else {
                                orState(rsrc, UNCHANGED);
                                // decoration.addSuffix("=?");
                            }
                        } else {
                            decoration.addSuffix(" ?* ");
                        }

                        if (rsrc instanceof IProject) {
                            Repository repo = mapped.getRepository();
                            try {
                                String branch = repo.getBranch();
                                if (repo.isStGitMode()) {
                                    String patch = repo.getPatch();
                                    decoration.addSuffix(" [StGit " + patch + "@" + branch + "]");
                                } else {
                                    RepositoryState repositoryState = repo.getRepositoryState();
                                    String statename;
                                    if (repositoryState.equals(RepositoryState.SAFE))
                                        statename = "";
                                    else
                                        statename = repositoryState.getDescription() + " ";
                                    decoration.addSuffix(" [Git " + statename + "@ " + branch + "]");
                                }
                            } catch (IOException e) {
                                e.printStackTrace();
                                decoration.addSuffix(" [Git ?]");
                            }
                            decoration.addOverlay(UIIcons.OVR_SHARED);
                        }

                    } else {
                        if (Team.isIgnoredHint(rsrc)) {
                            decoration.addSuffix("(ignored)");
                        } else {
                            decoration.addPrefix(">");
                            decoration.addSuffix("(untracked)");
                            orState(rsrc.getParent(), CHANGED);
                        }
                    }
                } else {
                    if (!(rsrc instanceof IContainer)) {
                        decoration.addSuffix("(deprecated)"); // Will drop on
                        // commit
                        decoration.addOverlay(UIIcons.OVR_PENDING_REMOVE);
                        orState(rsrc.getParent(), CHANGED);
                    }
                }
            } else {
                if (entry.getStage() != GitIndex.STAGE_0) {
                    decoration.addSuffix("(conflict)");
                    decoration.addOverlay(UIIcons.OVR_CONFLICT);
                    orState(rsrc.getParent(), CHANGED);
                    return;
                }

                if (blob == null) {
                    decoration.addOverlay(UIIcons.OVR_PENDING_ADD);
                    orState(rsrc.getParent(), CHANGED);
                } else {

                    if (entry.isAssumedValid()) {
                        decoration.addOverlay(UIIcons.OVR_ASSUMEVALID);
                        return;
                    }

                    decoration.addOverlay(UIIcons.OVR_SHARED);

                    if (entry.isModified(mapped.getWorkDir(), true)) {
                        decoration.addPrefix(">");
                        decoration.addSuffix("(not updated)");
                        orState(rsrc.getParent(), CHANGED);
                    } else {
                        if (!entry.getObjectId().equals(blob.getId()))
                            decoration.addPrefix(">");
                        else
                            decoration.addPrefix(""); // set it to avoid further calls
                    }
                }
            }
        }
    } catch (IOException e) {
        decoration.addSuffix("?");
        // If we throw an exception Eclipse will log the error and
        // unregister us thereby preventing us from dragging down the
        // entire workbench because we are crashing.
        //
        throw new RuntimeException(UIText.Decorator_failedLazyLoading, e);
    } catch (CoreException e) {
        throw new RuntimeException(UIText.Decorator_failedLazyLoading, e);
    }
}

From source file:org.talend.mdm.repository.ui.navigator.MDMServerDecorator.java

License:Open Source License

private void decorateModifiedObject(IRepositoryViewObject viewObj, IDecoration decoration) {
    CommandStack stack = CommandManager.getInstance().findCommandStack(viewObj.getId());
    if (stack != null) {
        ICommand command = stack.getValidDeployCommand();
        switch (command.getCommandType()) {
        case ICommand.CMD_ADD:
            decoration.addOverlay(IMG_NEW, IDecoration.BOTTOM_RIGHT);
            return;
        case ICommand.CMD_DELETE:
            decoration.addOverlay(IMG_DELETE, IDecoration.BOTTOM_RIGHT);
            return;
        case ICommand.CMD_MODIFY:
        case ICommand.CMD_RENAME:
            decoration.addPrefix("> "); //$NON-NLS-1$
            decoration.addOverlay(IMG_MODIFY, IDecoration.BOTTOM_RIGHT);
            return;

        }/*www  .ja v  a2 s  . co m*/
    }
}

From source file:org.tigris.subversion.subclipse.ui.decorator.SVNDecoratorConfiguration.java

License:Open Source License

/**
  * add a prefix and a suffix depending on format string and the bindings
  * @param decoration/*from   ww  w.j  a va2  s  . c o m*/
  * @param format
  * @param bindings
  */
public static void decorate(IDecoration decoration, IDecoratorComponent[][] format, Map bindings) {

    String[] prefixSuffix = decorate(format, bindings);
    decoration.addPrefix(prefixSuffix[0]);
    decoration.addSuffix(prefixSuffix[1]);
}

From source file:unc.lib.cdr.workbench.views.OriginalAndDivDecorator.java

License:Apache License

@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof OriginalStub) {
        decorateOriginalStub((OriginalStub) element, decoration);
        return;/*www. j a  va  2  s. c om*/
    }
    OriginalFileStore r = null;
    boolean isDiv = false;
    boolean isFile = false;
    // added/captured, queued/staged BR
    List<String> labels = new ArrayList<String>();
    if (element instanceof OriginalFileStore) {
        r = (OriginalFileStore) element;
        if (r.isAttached()) {
            IFileInfo info = r.fetchInfo();
            if (info.exists() && !info.isDirectory())
                isFile = true;
        }
        // add prefix of "../" to these when not under volume root
        if (r.getWrapped().getParent() != null) {
            if (r.getOriginalStub().getStores().contains(r)) {
                if (!r.getOriginalStub().getVolumeRootStore().getWrapped().equals(r.getWrapped().getParent())) {
                    decoration.addPrefix(".../");
                }
            }
        }
    } else if (DivTypeImpl.class.isInstance(element)) {
        isDiv = true;
        DivType d = (DivType) element;
        if (METSConstants.Div_File.equals(d.getTYPE())) {
            isFile = true;
        }
        Object adapted = Platform.getAdapterManager().getAdapter(d, OriginalFileStore.class);
        if (adapted != null && adapted instanceof OriginalFileStore) {
            r = (OriginalFileStore) adapted;
        }

        // Descriptions Decor
        boolean hasUserEdited = false;
        boolean hasCrosswalked = false;
        for (MdSecType md : d.getDmdSec()) {
            String st = md.getSTATUS();
            if (METSConstants.MD_STATUS_CROSSWALK_LINKED.equals(st)
                    || METSConstants.MD_STATUS_CROSSWALK_USER_LINKED.equals(st)) {
                hasCrosswalked = true;
            } else if (METSConstants.MD_STATUS_USER_EDITED.equals(st)) {
                hasUserEdited = true;
            }
        }
        if (hasUserEdited) {
            decoration.addOverlay(Icon.UserEditedDecor.getImageDescriptor(), IDecoration.TOP_RIGHT);
        } else if (hasCrosswalked) {
            decoration.addOverlay(Icon.CrosswalkedDecor.getImageDescriptor(), IDecoration.TOP_RIGHT);
        }

        // ACL Decor
        boolean hasCrosswalkedACL = false;
        boolean hasUserACL = false;
        for (MdSecType md : d.getMdSec()) {
            if (MetsPackage.eINSTANCE.getAmdSecType_RightsMD().equals(md.eContainingFeature())) {
                String st = md.getSTATUS();
                if (METSConstants.MD_STATUS_CROSSWALK_LINKED.equals(st)
                        || METSConstants.MD_STATUS_CROSSWALK_USER_LINKED.equals(st)) {
                    hasCrosswalkedACL = true;
                } else if (METSConstants.MD_STATUS_USER_EDITED.equals(st)) {
                    hasUserACL = true;
                }
            }
        }
        if (hasUserACL) {
            decoration.addOverlay(Icon.ACLDecor.getImageDescriptor(), IDecoration.TOP_LEFT);
        } else if (hasCrosswalkedACL) {
            decoration.addOverlay(Icon.ACLGrayDecor.getImageDescriptor(), IDecoration.TOP_LEFT);
        }

        // add labels for links of which this div is the object
        for (SmLinkType sml : METSUtils.getObjectLinks(d)) {
            labels.add(METSConstants.getLinkForArcRole(sml.getArcrole()).label);
        }

    }

    ImageDescriptor overlay = null;
    if (r != null && r.getProject() != null && r.getProject().isOpen()) {
        boolean captured = false;
        if (r.isAttached() && isFile) {
            long byteLength = r.fetchInfo().getLength();
            labels.add(IResourceConstants.humanReadableByteCount(byteLength, true));
        }
        if (r.getMetsDivType() != null) {
            captured = true;
            if (!isDiv) {
                labels.add("captured");
            }
        }
        // staged location == original location
        SharedStagingArea prestage = StagingPlugin.getDefault().getStages()
                .findMatchingArea(r.getWrapped().toURI());
        if (prestage != null && r.getStagingLocatorType() == null) {
            labels.add("pre-staged: " + prestage.getName());
        }
        if (r.getStagingLocatorType() != null) {
            // captured file (original or the div)
            overlay = Icon.StagedDecor.getImageDescriptor();
            URI uri = URI.create(r.getStagingLocatorType().getHref());
            if (uri.isAbsolute()) {
                labels.add("staged");
            } else {
                labels.add("locally staged");
            }
        } else {
            if (captured && isFile) {
                overlay = Icon.CaptureDecor.getImageDescriptor();
                labels.add("queued");
            }
        }
    } else {
        if (isDiv) {
            labels.add("added");
        }
    }
    if (overlay != null) {
        decoration.addOverlay(overlay, IDecoration.BOTTOM_RIGHT);
    }
    StringBuilder sb = new StringBuilder();
    if (labels.size() > 0) {
        sb.append("  [");
        sb.append(labels.remove(0));
        for (String label : labels) {
            sb.append("  ").append(label);
        }
        sb.append("]");
    }
    decoration.addSuffix(sb.toString());
}

From source file:unc.lib.cdr.workbench.views.OriginalAndDivDecorator.java

License:Apache License

private void decorateOriginalStub(OriginalStub stub, IDecoration decoration) {
    decoration.addPrefix("Originals on ");
    List<String> labels = new ArrayList<String>();
    // ejected overlay for detached disks
    if (!stub.isAttached()) {
        decoration.addOverlay(Icon.EjectedDecore.getImageDescriptor(), IDecoration.TOP_RIGHT);
        labels.add("ejected");
    }/* ww  w .ja  va  2s. c o m*/
    labels.add(stub.getVolumeType());
    if (labels.size() > 0) {
        // decoration.setForegroundColor(org.eclipse.swt.graphics.);
        StringBuilder sb = new StringBuilder();
        sb.append("  [");
        sb.append(labels.remove(0));
        for (String label : labels) {
            sb.append("  ").append(label);
        }
        sb.append("]");
        decoration.addSuffix(sb.toString());
    }
}