Search in sources :

Example 1 with HyperlinkStyler

use of org.bndtools.utils.jface.HyperlinkStyler in project bndtools by bndtools.

the class RepositoryTreeLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    int index = cell.getColumnIndex();
    if (element instanceof RepositoryPlugin) {
        if (index == 0) {
            RepositoryPlugin repo = (RepositoryPlugin) element;
            cell.setText(repo.getName());
            Image image;
            if (RepoUtils.isWorkspaceRepo(repo))
                image = projectImg;
            else if (isRemoteRepo((RepositoryPlugin) element))
                image = remoteRepoImg;
            else
                image = localRepoImg;
            cell.setImage(image);
        }
    } else if (element instanceof Project) {
        if (index == 0) {
            @SuppressWarnings("resource") Project project = (Project) element;
            StyledString label = new StyledString(project.getName());
            if (showRepoId)
                label.append("  [Workspace]", StyledString.QUALIFIER_STYLER);
            cell.setText(label.getString());
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(projectImg);
        }
    } else if (element instanceof ProjectBundle) {
        if (index == 0) {
            StyledString label = new StyledString(((ProjectBundle) element).getBsn());
            if (showRepoId)
                label.append("  [Workspace]", StyledString.QUALIFIER_STYLER);
            cell.setText(label.getString());
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(bundleImg);
        }
    } else if (element instanceof RepositoryBundle) {
        if (index == 0) {
            RepositoryBundle bundle = (RepositoryBundle) element;
            StyledString label = new StyledString(bundle.getText());
            if (showRepoId)
                label.append("  [" + bundle.getRepo().getName() + "]", StyledString.QUALIFIER_STYLER);
            cell.setText(label.getString());
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(bundleImg);
        }
    } else if (element instanceof RepositoryBundleVersion) {
        if (index == 0) {
            RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) element;
            String versionText = bundleVersion.getText();
            if (versionText.contains(" ⇩")) {
                versionText = versionText.replaceAll(" ⇩", "");
                cell.setImage(arrowImg);
            }
            StyledString styledString = new StyledString(versionText, StyledString.COUNTER_STYLER);
            cell.setText(styledString.getString());
            cell.setStyleRanges(styledString.getStyleRanges());
        }
    } else if (element instanceof RepositoryResourceElement) {
        RepositoryResourceElement resourceElem = (RepositoryResourceElement) element;
        StyledString label = new StyledString();
        label.append(resourceElem.getIdentity()).append(" ");
        label.append(resourceElem.getVersionString(), StyledString.COUNTER_STYLER);
        cell.setText(label.getString());
        cell.setStyleRanges(label.getStyleRanges());
        cell.setImage(matchImg);
    } else if (element instanceof ContinueSearchElement) {
        StyledString label = new StyledString("Continue Search on JPM4J.org...", new HyperlinkStyler());
        cell.setText(label.getString());
        cell.setStyleRanges(label.getStyleRanges());
    } else if (element instanceof LoadingContentElement) {
        cell.setText("Loading content...");
        cell.setImage(loadingImg);
    } else if (element != null) {
        // Catch-all
        cell.setText(element.toString());
    }
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) Project(aQute.bnd.build.Project) HyperlinkStyler(org.bndtools.utils.jface.HyperlinkStyler)

Aggregations

Project (aQute.bnd.build.Project)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 HyperlinkStyler (org.bndtools.utils.jface.HyperlinkStyler)1 StyledString (org.eclipse.jface.viewers.StyledString)1 Image (org.eclipse.swt.graphics.Image)1