Java Code Examples for org.eclipse.jface.viewers.ViewerCell#setStyleRanges()

The following examples show how to use org.eclipse.jface.viewers.ViewerCell#setStyleRanges() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloneDiffTooltip.java    From JDeodorant with MIT License 6 votes vote down vote up
public void update(ViewerCell cell) { 
	Object element = cell.getElement();
	if (element instanceof CloneStructureNode){
		cell.setText("CloneStructureNode");
	}
	if (element instanceof PreconditionViolation){
		PreconditionViolation preconditionViolation = (PreconditionViolation) element;
		StyledString styledString = preconditionViolation.getStyledViolation();
		cell.setText(styledString.getString());
		cell.setStyleRanges(styledString.getStyleRanges());
		cell.setImage(PRECONDITION_VIOLATION_IMAGE);
	}
	if (element instanceof Suggestion){
		Suggestion suggestion = (Suggestion) element;
		cell.setText(suggestion.getSuggestion());
		cell.setImage(SUGGESTION_IMAGE);
	}
}
 
Example 2
Source File: TypeLabelProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    StyledString styledString = getStyledString(element);
    cell.setText(styledString.getString());

    IStatus status = validator.validate(element);
    if (status.getSeverity() == IStatus.ERROR) {
        cell.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR));
        cell.setForeground(errorColor);
    } else {
        cell.setForeground(null);
        cell.setImage(null);
    }
    cell.setStyleRanges(styledString.getStyleRanges());
}
 
Example 3
Source File: ContractInputTypeCellLabelProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    super.update(cell);
    final ContractInput element = (ContractInput) cell.getElement();
    final String text = getText(element);
    final StyledString styledString = new StyledString(text, new StyledString.Styler() {

        @Override
        public void applyStyles(TextStyle textStyle) {
            if (element.getType() == ContractInputType.DATE) {
                textStyle.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
            }
        }
    });
    cell.setText(styledString.getString());
    cell.setStyleRanges(styledString.getStyleRanges());
}
 
Example 4
Source File: TreeLabelProvider.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void update(ViewerCell cell) {
  Object element = cell.getElement();
  if (element != null && element instanceof ITreeElement) {
    ITreeElement treeElement = (ITreeElement) element;

    StyledString styledString = treeElement.getStyledText();
    if (styledString != null) {
      cell.setText(styledString.toString());
      cell.setStyleRanges(styledString.getStyleRanges());
    } else {
      cell.setText(null);
    }

    cell.setImage(treeElement.getImage());
  }
}
 
Example 5
Source File: XViewerStyledTextLabelProvider.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void update(ViewerCell cell) {
   Object element = cell.getElement();

   StyledString styledString = getStyledText(element, cell.getColumnIndex());
   String newText = styledString.toString();

   StyleRange[] oldStyleRanges = cell.getStyleRanges();
   StyleRange[] newStyleRanges = isOwnerDrawEnabled() ? styledString.getStyleRanges() : null;

   if (!Arrays.equals(oldStyleRanges, newStyleRanges)) {
      cell.setStyleRanges(newStyleRanges);
   }

   cell.setText(newText);
   cell.setImage(getColumnImage(element, cell.getColumnIndex()));
   cell.setFont(getFont(element, cell.getColumnIndex()));
   cell.setForeground(getForeground(element, cell.getColumnIndex()));
   cell.setBackground(getBackground(element, cell.getColumnIndex()));

   // no super call required. changes on item will trigger the refresh.
}
 
Example 6
Source File: CSVLabelProvider.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 */
@Override
public void update(final ViewerCell cell) {
	final CSVRow element = (CSVRow) cell.getElement();
	final int index = cell.getColumnIndex();
	final String columnText = getColumnText(element, index);
	cell.setText(columnText);
	cell.setImage(null);
	if (searchText != null && searchText.length() > 0) {
		final int intRangesCorrectSize[] = SearchResultStyle.getSearchTermOccurrences(searchText, columnText);
		final List<StyleRange> styleRange = new ArrayList<>();
		for (int i = 0; i < intRangesCorrectSize.length / 2; i++) {
			final StyleRange myStyleRange = new StyleRange(0, 0, null, searchColor);
			myStyleRange.start = intRangesCorrectSize[i];
			myStyleRange.length = intRangesCorrectSize[++i];
			styleRange.add(myStyleRange);
		}
		cell.setStyleRanges(styleRange.toArray(new StyleRange[styleRange.size()]));
	} else {
		cell.setStyleRanges(null);
	}

	super.update(cell);
}
 
Example 7
Source File: ServerLabelProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void update ( final ViewerCell cell, final ServerEndpoint element )
{
    final StyledString str = new StyledString ();

    final boolean running = element.isRunning ();

    str.append ( element.getLabel () );

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

    if ( element.getError () != null )
    {
        cell.setImage ( this.errorImage );
    }
    else
    {
        cell.setImage ( running ? this.runningImage : this.stoppedImage );
    }
}
 
Example 8
Source File: FlagsDetailsPart.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void update ( final ViewerCell cell )
{
    final Object ele = cell.getElement ();
    if ( ele instanceof GroupEntry )
    {
        cell.setText ( String.format ( Messages.FlagsDetailsPart_GroupSumFormat, ( (GroupEntry)ele ).getActiveCount (), ( (GroupEntry)ele ).getCount () ) );
    }
    else if ( ele instanceof AttributeEntry )
    {
        final StyledString str = new StyledString ();

        if ( ( (AttributeEntry)ele ).isActive () )
        {
            str.append ( Messages.FlagsDetailsPart_ActiveMarker, this.activeStyler );
        }
        else
        {
            str.append ( Messages.FlagsDetailsPart_InactiveMarker, this.inactiveStyler );
        }

        cell.setText ( str.getString () );
        cell.setStyleRanges ( str.getStyleRanges () );
    }
}
 
Example 9
Source File: AbapGitStagingLabelProvider.java    From ADT_Frontend with MIT License 6 votes vote down vote up
private void updateObjectCell(ViewerCell cell, IAbapGitObject object) {
	StyledString text = new StyledString();
	if (object.getType() == null || object.getType().isEmpty()) { //non-code and meta files
		text.append(object.getName().toLowerCase(Locale.ENGLISH), this.customStyler);
		cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER));
	} else {
		if (object.eContainer() instanceof IIgnoredObjects) { //Ignored Objects will be shown as greyed out
			text.append(object.getName().toUpperCase(Locale.ENGLISH), this.grayStyler);
		} else {
			text.append(object.getName().toUpperCase(Locale.ENGLISH));
		}
		text.append(DASH, this.grayStyler).append(object.getType(), this.grayStyler);
		cell.setImage(getObjectImage(object));
	}

	cell.setText(text.getString());
	cell.setStyleRanges(text.getStyleRanges());
}
 
Example 10
Source File: DataStyledTreeLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
	if (cell.getElement() instanceof Data) {
		Data d = (Data) cell.getElement();
		StyledString styledString = new StyledString();

		String decoration = " -- " + getTypeLabel(d);
		if (d.isTransient()) {
			styledString.append(d.getName(), italicGrey);
		} else {
			styledString.append(d.getName(), null);
		}
		styledString.append(decoration, StyledString.DECORATIONS_STYLER);
		if(d.getDefaultValue() != null
				&& d.getDefaultValue().getName() != null
				&& !d.getDefaultValue().getName().isEmpty()){
			String content = d.getDefaultValue().getName();
			content = Messages.defaultValue+": "  + content.replaceAll("\n", " ")  ;
			if(content.length() > 150) {
			    content = content.substring(0, 150) + "...";
			}
			styledString.append(" -- ",StyledString.DECORATIONS_STYLER) ;
			styledString.append(content, StyledString.QUALIFIER_STYLER);
		}
		cell.setText(styledString.getString());
		cell.setImage(getImage(d)) ;
		cell.setStyleRanges(styledString.getStyleRanges());
	}
}
 
Example 11
Source File: OutlineStyledLabelProvider.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@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)));
    }
}
 
Example 12
Source File: SearchCellLabelProvider.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    final String text = getText(element);
    cell.setText(text);
    cell.setImage(getImage(element));
    cell.setFont(getFont(element));
    if (filterString != null && !filterString.isEmpty()) {
        int filterIndex = text.indexOf(filterString);
        StyleRange styleRange = new StyleRange(filterIndex, filterString.length(), null, hightLight);
        cell.setStyleRanges(new StyleRange[] { styleRange });
    } else {
        cell.setStyleRanges(null);
    }
}
 
Example 13
Source File: ServerLabelProvider.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected void update ( final ViewerCell cell, final ServerDescriptor element )
{
    final StyledString str = new StyledString ();

    final boolean running = element.isRunning ();

    str.append ( element.getLabel () );

    final String add = element.getAdditionalLabel ();
    if ( add != null )
    {
        str.append ( ' ' );
        str.append ( add, StyledString.QUALIFIER_STYLER );
    }

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

    if ( element.getError () != null )
    {
        cell.setImage ( this.errorImage );
    }
    else
    {
        cell.setImage ( running ? this.runningImage : this.stoppedImage );
    }
}
 
Example 14
Source File: StyledFilterLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    if (cell.getElement() instanceof ActorFilter) {
        ActorFilter filter = (ActorFilter) cell.getElement();
        ConnectorDefinition def = defStore.getDefinition(filter.getDefinitionId(),filter.getDefinitionVersion()) ;
        StyledString styledString = new StyledString();

        styledString.append(getText(filter), null);
        styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
        String connectorType = filter.getDefinitionId() +" ("+filter.getDefinitionVersion()+")";
        styledString.append(connectorType, StyledString.DECORATIONS_STYLER);
        if(filter.getEvent() != null && !filter.getEvent().isEmpty()){
            styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
            styledString.append(filter.getEvent(), StyledString.COUNTER_STYLER);
        }
        if(def == null){
            styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

                @Override
                public void applyStyles(TextStyle textStyle) {
                    textStyle.strikeout = true ;
                }
            }) ;
            styledString.append(" ");
            styledString.append(Messages.bind(Messages.filterDefinitionNotFound,filter.getDefinitionId() + " ("+filter.getDefinitionVersion()+")")) ;
        }

        cell.setText(styledString.getString());
        cell.setImage(getImage(filter)) ;
        cell.setStyleRanges(styledString.getStyleRanges());
    }
}
 
Example 15
Source File: AbapGitStagingLabelProvider.java    From ADT_Frontend with MIT License 5 votes vote down vote up
private void updateFileCell(ViewerCell cell, IAbapGitFile file) {
	StyledString text = new StyledString();
	if (file.eContainer().eContainer() instanceof IIgnoredObjects) { //Ignored files will be shown as greyed out
		text.append(file.getName().toLowerCase(Locale.ENGLISH), this.grayStyler);
	} else {
		text.append(file.getName().toLowerCase(Locale.ENGLISH));
	}
	text.append(DASH, this.grayStyler).append(file.getPath(), this.grayStyler);
	cell.setText(text.getString());
	cell.setStyleRanges(text.getStyleRanges());
	cell.setImage(getFileImage(file));
}
 
Example 16
Source File: DeployTreeLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    if (cell.getElement() instanceof IDisplayable) {
        final IDisplayable displayable = (IDisplayable) cell.getElement();
        final StyledString styledString = displayable.getStyledString();
        cell.setText(styledString.getString());
        cell.setImage(displayable.getIcon());
        cell.setStyleRanges(styledString.getStyleRanges());
    }
}
 
Example 17
Source File: FileStoreLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
    if (cell.getElement() instanceof IRepositoryFileStore) {
        final IRepositoryFileStore fileStore = (IRepositoryFileStore) cell.getElement();
        final StyledString styledString = new StyledString();
        styledString.append(fileStore.getName());
        cell.setText(styledString.getString());
        cell.setImage(getImage(cell.getElement()));
        contentValidation(fileStore, styledString, cell);

        cell.setStyleRanges(styledString.getStyleRanges());
    }
}
 
Example 18
Source File: ContractInputLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(final ViewerCell cell) {
    super.update(cell);
    final ContractInput element = (ContractInput) cell.getElement();
    final StyledString styledString = getStyledString(element);
    cell.setText(styledString.toString());
    cell.setStyleRanges(styledString.getStyleRanges());
    cell.setImage(getImage(element));
}
 
Example 19
Source File: StyledConnectorLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(ViewerCell cell) {
	if (cell.getElement() instanceof Connector) {
		Connector connector = (Connector) cell.getElement();
		ConnectorDefinition def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ;
		if(def == null){
			def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ;
		}
		StyledString styledString = new StyledString();

		styledString.append(getText(connector), null);
		styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
		String connectorType = connector.getDefinitionId() +" ("+connector.getDefinitionVersion()+")";
		styledString.append(connectorType, StyledString.DECORATIONS_STYLER);
		EObject parent = connector.eContainer();
           if (!(parent instanceof Expression)) {
			if(connector.getEvent() != null && !connector.getEvent().isEmpty()){
				styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ;
				styledString.append(connector.getEvent(), StyledString.COUNTER_STYLER);
			}
		}
		if(def == null){
			styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() {

				@Override
				public void applyStyles(TextStyle textStyle) {
					textStyle.strikeout = true ;
				}
			}) ;
			styledString.append(" ");
			styledString.append(Messages.bind(Messages.connectorDefinitionNotFound,connector.getDefinitionId() + " ("+connector.getDefinitionVersion()+")")) ;
		}

		cell.setText(styledString.getString());
		cell.setImage(getImage(connector)) ;
		cell.setStyleRanges(styledString.getStyleRanges());
	}
}
 
Example 20
Source File: DocumentStyledLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(final ViewerCell cell) {
    final Object element = cell.getElement();
    if (element instanceof Document) {
        final Document document = (Document) element;
        final StyledString styledString = new StyledString();
        styledString.append(document.getName());
        final String decoration = " -- " + getTypeLabel(document);
        styledString.append(decoration, StyledString.DECORATIONS_STYLER);
        styledString.append(" -- ", StyledString.DECORATIONS_STYLER);
        cell.setText(styledString.getString());
        cell.setStyleRanges(styledString.getStyleRanges());
        cell.setImage(getImage(element));
    }
}