Example usage for org.eclipse.jface.viewers ViewerCell setStyleRanges

List of usage examples for org.eclipse.jface.viewers ViewerCell setStyleRanges

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell setStyleRanges.

Prototype

public void setStyleRanges(StyleRange[] styleRanges) 

Source Link

Document

Set the style ranges to be applied on the text label Note: Requires StyledCellLabelProvider with owner draw enabled.

Usage

From source file:com.netxforge.netxstudio.screens.f3.support.NetworkTreeLabelProvider.java

License:Open Source License

private void updateColumn1(ViewerCell cell, Object element) {

    StyledString styledString = new StyledString();
    // Styler expressionColorStyle = StyledString.createColorRegistryStyler(
    // EXPRESSION_COLOR_STYLER, null);
    Image img = null;//www  .j a  v a  2  s  .  co m
    if (element instanceof Component) {
        Component c = (Component) element;
        if (c.eIsSet(LibraryPackage.Literals.COMPONENT__CAPACITY_EXPRESSION_REF)) {
            // styledString.append(" C ", expressionColorStyle);
            // cell.setText(styledString.getString());
            img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/Expression_H.png");
            cell.setImage(img);
            cell.setStyleRanges(styledString.getStyleRanges());
        } else {
            cell.setImage(null);
        }
    }

}

From source file:com.netxforge.netxstudio.screens.f3.support.NetworkTreeLabelProvider.java

License:Open Source License

private void updateColumn2(ViewerCell cell, Object element) {

    StyledString styledString = new StyledString();
    // Styler expressionColorStyle = StyledString.createColorRegistryStyler(
    // EXPRESSION_COLOR_STYLER, null);
    Image img = null;//from  w w w  .j a va2s  . c  o m

    if (element instanceof Component) {
        Component c = (Component) element;

        if (c.eIsSet(LibraryPackage.Literals.COMPONENT__UTILIZATION_EXPRESSION_REF)) {
            // styledString.append(" ,U ", expressionColorStyle);
            // cell.setText(styledString.getString());
            img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/Expression_H.png");
            cell.setImage(img);
            cell.setStyleRanges(styledString.getStyleRanges());
        } else {
            cell.setImage(null);
        }
    }
}

From source file:com.netxforge.netxstudio.screens.f3.support.NetworkTreeLabelProvider.java

License:Open Source License

private void updateColumn3(ViewerCell cell, Object element) {

    StyledString styledString = new StyledString();
    if (element instanceof Component) {
        Component c = (Component) element;
        int size = c.getToleranceRefs().size();
        if (size > 0) {
            cell.setText(new Integer(size).toString());
            cell.setStyleRanges(styledString.getStyleRanges());
        }/*ww  w  . j  ava2 s .  com*/
    }
}

From source file:com.netxforge.netxstudio.screens.f3.support.NetworkTreeLabelProvider.java

License:Open Source License

private void updateColumn0(ViewerCell cell, Object element) {
    if (element instanceof Operator) {

        Operator operator = (Operator) element;

        StyledString styledString = new StyledString(operator.getName() != null ? operator.getName() : "?",
                null);//  w  w w .  java 2s. c o m
        cell.setText(styledString.getString());
        Image img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                "icons/full/obj16/Company_H.png");
        cell.setImage(img);
        cell.setStyleRanges(styledString.getStyleRanges());
    }

    if (element instanceof Network) {

        Network network = (Network) element;

        StyledString styledString = new StyledString(network.getName() != null ? network.getName() : "?", null);
        // String decoration = " (" + network.getFunctions().size() +
        // " Functions)"
        // + " (" + network.getFunctions().size() + " Equipments)";
        // styledString.append(decoration, StyledString.COUNTER_STYLER);
        cell.setText(styledString.getString());
        Image img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                "icons/full/obj16/Network_H.png");
        cell.setImage(img);
        cell.setStyleRanges(styledString.getStyleRanges());
    }

    if (element instanceof Node) {

        Node node = (Node) element;

        StyledString styledString = new StyledString(node.getNodeID() != null ? node.getNodeID() : "?", null);
        cell.setText(styledString.getString());
        Image img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                "icons/full/obj16/Node_H.png");
        cell.setImage(img);
        cell.setStyleRanges(styledString.getStyleRanges());
    }

    if (element instanceof Component) {

        Component c = (Component) element;
        StyledString styledString = new StyledString();

        Styler lifecycleColorStyler = StyledString.createColorRegistryStyler(LIFECYCLE_COLOR_STYLER, null);
        int lifeCycleState = StudioUtils.lifecycleState(c.getLifecycle());

        styledString.append(StudioUtils.componentName(c), null);

        if (element instanceof Function) {
            cell.setImage(ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/Function_H.png"));
        }
        if (element instanceof Equipment) {
            cell.setImage(ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/Equipment_H.png"));

        }

        Styler metricColorStyler = StyledString.createColorRegistryStyler(METRIC_COLOR_STYLER, null);

        // Add Resources info.
        if (!c.getResourceRefs().isEmpty()) {
            String decoration = " (" + c.getResourceRefs().size() + " Res.)";
            styledString.append(decoration, StyledString.COUNTER_STYLER);
        }

        // Add Metrics info.
        if (!c.getMetricRefs().isEmpty()) {
            String decoration = " (" + c.getMetricRefs().size() + " Metrics)";
            styledString.append(decoration, metricColorStyler);
        }

        // Add Life Cycle info.
        if (lifeCycleState != StudioUtils.LIFECYCLE_NOTSET) {
            String decoration = " (" + StudioUtils.lifecycleText(lifeCycleState) + ")";
            styledString.append(decoration, lifecycleColorStyler);
        }

        cell.setText(styledString.getString());
        cell.setStyleRanges(styledString.getStyleRanges());

    }

    if (element instanceof Relationship) {

        Styler xColorStyler = StyledString.createColorRegistryStyler(REL_NOTCONNECTED_COLOR_STYLER, null);

        Relationship rel = (Relationship) element;
        StyledString styledString = new StyledString(rel.getName() != null ? rel.getName() : "?", null);

        StringBuffer decoration = new StringBuffer();
        decoration.append(" (");
        if (rel.getNodeID1Ref() != null) {
            decoration.append(rel.getNodeID1Ref().getNodeID());
            styledString.append(decoration.toString(), StyledString.COUNTER_STYLER);
        } else {
            styledString.append(decoration.toString(), StyledString.COUNTER_STYLER);
            styledString.append(" x", xColorStyler);
        }

        decoration = new StringBuffer();
        decoration.append(" <--> ");

        if (rel.getNodeID2Ref() != null) {
            decoration.append(rel.getNodeID2Ref().getNodeID());
            styledString.append(decoration.toString(), StyledString.COUNTER_STYLER);
        } else {
            styledString.append(decoration.toString(), StyledString.COUNTER_STYLER);
            styledString.append("x", xColorStyler);

        }
        decoration = new StringBuffer();
        decoration.append(" )");

        styledString.append(decoration.toString(), StyledString.COUNTER_STYLER);

        cell.setText(styledString.getString());

        Image img;
        if (element instanceof FunctionRelationship) {
            img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/FunctionRelationship_H.png");
            cell.setImage(img);
        }
        if (element instanceof EquipmentRelationship) {
            img = ResourceManager.getPluginImage("com.netxforge.netxstudio.models.edit",
                    "icons/full/obj16/EquipmentRelationship_H.png");
            cell.setImage(img);
        }

        cell.setStyleRanges(styledString.getStyleRanges());
    }
}

From source file:com.netxforge.netxstudio.screens.f4.support.MetricTreeLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {

    if (cell.getElement() instanceof Metric) {
        Metric metric = (Metric) cell.getElement();
        String txt = "";
        switch (cell.getColumnIndex()) {

        case 0: {
            txt = metric.getName() != null ? metric.getName() : "";
        }/*w  w  w. j a v a  2 s.co  m*/
            break;
        case 1: {
            txt = metric.getDescription() != null ? metric.getDescription() : "";
        }
            break;
        case 2: {
            txt = metric.getUnitRef() != null ? metric.getUnitRef().getName() : "";
        }
            break;

        }

        StyledString styledString = new StyledString(txt, null);
        // String decoration = " (" +
        // metric.getCommitters().size() + " Committers)";
        // styledString.append(
        // decoration,
        // StyledString.COUNTER_STYLER
        // );
        cell.setText(styledString.getString());
        // cell.setImage(projectImage);
        cell.setStyleRanges(styledString.getStyleRanges());
    }
    super.update(cell);
}

From source file:com.netxforge.netxstudio.screens.LoadingLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {

    Object element = cell.getElement();
    if (element instanceof String) {
        // Do some styling on our loading string. .
        StyledString styledString = new StyledString();
        styledString.append((String) element, StyledString.COUNTER_STYLER);
        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());
    }/*www .  j a  va2  s  .c om*/
    // We only support String (for now).
    super.update(cell);
}

From source file:com.puppetlabs.geppetto.pp.dsl.ui.editor.findrefs.ReferenceSearchResultLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    Object o = cell.getElement();
    StyledString st = getStyledText(o);// w w w .  ja  v a  2s . c om
    if (st == null)
        st = new StyledString("<cell with null element>");
    cell.setText(st.toString());
    cell.setStyleRanges(st.getStyleRanges());
    cell.setImage(getImage(o));
}

From source file:com.reprezen.swagedit.core.editor.outline.OutlineStyledLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();

    if (element instanceof AbstractNode) {
        StyledString styledString = getStyledString((AbstractNode) element);

        cell.setText(styledString.toString());
        cell.setStyleRanges(styledString.getStyleRanges());
        cell.setImage(getImage(getIcon((AbstractNode) element)));
    }/*from   w  ww . ja v  a2  s.  c  o m*/
}

From source file:com.siteview.mde.internal.runtime.registry.RegistryBrowserLabelProvider.java

License:Open Source License

public void update(ViewerCell cell) {
    StyledString string = getStyledText(cell.getElement());
    cell.setText(string.getString());/* w w w .j  av  a 2 s.  c  o m*/
    cell.setStyleRanges(string.getStyleRanges());
    cell.setImage(getImage(cell.getElement()));
    super.update(cell);
}

From source file:com.siteview.mde.internal.ui.shared.target.StyledBundleLabelProvider.java

License:Open Source License

public void update(ViewerCell cell) {
    Object element = cell.getElement();
    StyledString styledString = getStyledString(element);
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setImage(getImage(element));//  ww w  .  j  av  a2s.c  o m
    super.update(cell);
}