List of usage examples for org.eclipse.jface.viewers ViewerCell setStyleRanges
public void setStyleRanges(StyleRange[] styleRanges)
From source file:org.eclipse.e4.tools.emf.ui.internal.common.ComponentLabelProvider.java
License:Open Source License
@Override public void update(final ViewerCell cell) { if (cell.getElement() instanceof EObject) { EObject o = (EObject) cell.getElement(); AbstractComponentEditor elementEditor = editor.getEditor(o.eClass()); if (elementEditor != null) { String label = elementEditor.getLabel(o); String detailText = elementEditor.getDetailLabel(o); Styler styler = null;//from w ww.jav a 2s . c om if (o instanceof MUIElement) { if (!((MUIElement) o).isVisible() && !((MUIElement) o).isToBeRendered()) { label += "<" + Messages.ComponentLabelProvider_invisible + "/" //$NON-NLS-1$//$NON-NLS-2$ + Messages.ComponentLabelProvider_notrendered + ">"; //$NON-NLS-1$ styler = BOTH_STYLER; } else if (!((MUIElement) o).isVisible()) { label += "<" + Messages.ComponentLabelProvider_invisible + ">"; //$NON-NLS-1$//$NON-NLS-2$ styler = NOT_VISIBLE_STYLER; } else if (!((MUIElement) o).isToBeRendered()) { label += "<" + Messages.ComponentLabelProvider_notrendered + ">"; //$NON-NLS-1$ //$NON-NLS-2$ styler = NOT_RENDERED_STYLER; } } if (detailText == null) { StyledString styledString = new StyledString(label, styler); cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } else { StyledString styledString = new StyledString(label, styler); styledString.append(" - " + detailText, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } cell.setImage(elementEditor.getImage(o, cell.getControl().getDisplay())); } else { cell.setText(cell.getElement().toString()); } } else if (cell.getElement() instanceof VirtualEntry<?>) { String s = cell.getElement().toString(); if (font == null) { FontData[] data = cell.getControl().getFont().getFontData(); font = new Font(cell.getControl().getDisplay(), new FontData(data[0].getName(), data[0].getHeight(), SWT.ITALIC)); } cell.setFont(font); cell.setText(s); } else { cell.setText(cell.getElement().toString()); } }
From source file:org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.FindContributionDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); // TODO param getShell().setText(Messages.ContributionClassDialog_ShellTitle); if ("show-bundles".equals(mode)) { //$NON-NLS-1$ // TODO create icon } else if ("show-packages".equals(mode)) { //$NON-NLS-1$ // TODO create icon } else if ("show-icons".equals(mode)) { //$NON-NLS-1$ // TODO create icon } else {// w w w . j a va 2 s . co m titleImage = new Image(comp.getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/wizban/newclass_wiz.png")); //$NON-NLS-1$ setTitleImage(titleImage); } getShell().addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { javaClassImage.dispose(); if (titleImage != null) { titleImage.dispose(); } } }); javaClassImage = new Image(getShell().getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/obj16/class_obj.gif")); //$NON-NLS-1$ Composite container = new Composite(comp, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); container.setLayout(new GridLayout(2, false)); Label l = new Label(container, SWT.NONE); // TODO param l.setText(Messages.ContributionClassDialog_Label_Classname); final Text t = new Text(container, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH); t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // TODO param t.setMessage(Messages.ContributionClassDialog_FilterText_Message); new Label(container, SWT.NONE); viewer = new TableViewer(container, SWT.FULL_SELECTION | SWT.BORDER); GridData gd = new GridData(GridData.FILL_BOTH); viewer.getControl().setLayoutData(gd); viewer.setContentProvider(new ObservableListContentProvider()); viewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { ContributionData data = (ContributionData) cell.getElement(); StyledString styledString = new StyledString(); if ("show-bundles".equals(mode)) { //$NON-NLS-1$ styledString.append(data.bundleName, StyledString.DECORATIONS_STYLER); } else if ("show-packages".equals(mode)) { //$NON-NLS-1$ int dot = data.className.lastIndexOf("."); //$NON-NLS-1$ String packageName; if (dot >= 0) { packageName = data.className.substring(0, dot); } else { packageName = ""; //$NON-NLS-1$ } styledString.append(packageName, StyledString.DECORATIONS_STYLER); } else if ("show-icons".equals(mode)) { //$NON-NLS-1$ styledString.append(data.iconPath, null); if (data.bundleName != null) { styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ } if (data.sourceType != null) { styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$ } if (data.iconPath == null) { cell.setImage(javaClassImage); } } else { styledString.append(data.className, null); if (data.bundleName != null) { styledString.append(" - " + data.bundleName, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ } if (data.sourceType != null) { styledString.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$ styledString.append(data.sourceType + "", StyledString.COUNTER_STYLER); //$NON-NLS-1$ } if (data.iconPath == null) { cell.setImage(javaClassImage); } } cell.setText(styledString.getString()); cell.setStyleRanges(styledString.getStyleRanges()); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { okPressed(); } }); final WritableList list = new WritableList(); viewer.setInput(list); final ClassContributionCollector collector = getCollector(); t.addModifyListener(new ModifyListener() { private ContributionResultHandlerImpl currentResultHandler; @Override public void modifyText(ModifyEvent e) { if (currentResultHandler != null) { currentResultHandler.cancled = true; } list.clear(); currentResultHandler = new ContributionResultHandlerImpl(list); Filter filter = new Filter(project, t.getText()); collector.findContributions(filter, currentResultHandler); t.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { if (viewer.getTable().getItemCount() > 0) { viewer.getTable().setFocus(); viewer.getTable().select(0); } } } }); viewer.getTable().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); if ((e.keyCode == SWT.ARROW_UP) && (viewer.getTable().getSelectionIndex() == 0)) { t.setFocus(); } } }); } }); viewer.setFilters(new ViewerFilter[] { new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { ContributionData cd = (ContributionData) element; if ("show-bundles".equals(mode)) { //$NON-NLS-1$ // only add first item from each bundle boolean found = false; for (Iterator it = list.iterator(); it.hasNext();) { ContributionData cd2 = (ContributionData) it.next(); if (cd2.bundleName == null || cd2.bundleName.equals(cd.bundleName)) { if (found == false) { found = true; } else { return false; } } } return true; } else if ("show-packages".equals(mode)) { //$NON-NLS-1$ if (bundleFilter != null && bundleFilter.isEmpty() == false) { if (!bundleFilter.equals(cd.bundleName)) { return false; } } String packageName; int last = cd.className.lastIndexOf("."); //$NON-NLS-1$ if (last >= 0) { packageName = cd.className.substring(0, last); } else { packageName = ""; //$NON-NLS-1$ } // only add first item from each package boolean found = false; for (Iterator it = list.iterator(); it.hasNext();) { boolean matches = false; ContributionData cd2 = (ContributionData) it.next(); if (packageName.isEmpty() && cd2.className.contains(".") == false) { //$NON-NLS-1$ matches = true; } else if (cd2.className.startsWith(packageName + ".")) { //$NON-NLS-1$ matches = true; } if (matches) { if (found == false) { found = true; } else { return false; } } } return true; } else if ("show-icons".equals(mode)) { //$NON-NLS-1$ if (cd.iconPath == null) { return false; } if (bundleFilter != null && bundleFilter.isEmpty() == false) { if (!bundleFilter.equals(cd.bundleName)) { return false; } } if (packageFilter != null && packageFilter.isEmpty() == false) { if (!cd.className.startsWith(packageFilter + ".")) { //$NON-NLS-1$ return false; } } return true; } else { if (bundleFilter != null && bundleFilter.isEmpty() == false) { if (!bundleFilter.equals(cd.bundleName)) { return false; } } if (packageFilter != null && packageFilter.isEmpty() == false) { if (!cd.className.startsWith(packageFilter + ".")) { //$NON-NLS-1$ return false; } } return true; } } } }); StringBuilder sbFind = new StringBuilder(); if ("show-bundles".equals(mode)) { //$NON-NLS-1$ setTitle( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findBundle); sbFind.append( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findBundle); } else if ("show-packages".equals(mode)) { //$NON-NLS-1$ setTitle( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findPackage); sbFind.append( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findPackage); if (E.notEmpty(bundleFilter)) { sbFind.append(" " //$NON-NLS-1$ + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-3$ } } else if ("show-icons".equals(mode)) { //$NON-NLS-1$ setTitle( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findIcon); sbFind.append( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findIcon); if (E.notEmpty(bundleFilter)) { sbFind.append(" " //$NON-NLS-1$ + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-3$ } if (E.notEmpty(packageFilter)) { sbFind.append(" " //$NON-NLS-1$ + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inPackage + " " + packageFilter); //$NON-NLS-3$ } } else { setTitle( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findClass); sbFind.append( org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_findClass); if (E.notEmpty(bundleFilter)) { sbFind.append(" " //$NON-NLS-1$ + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inBundle + " " + bundleFilter); //$NON-NLS-3$ } if (E.notEmpty(packageFilter)) { sbFind.append(" " //$NON-NLS-1$ + org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages.FindContributionDialog_inPackage + " " + packageFilter); //$NON-NLS-3$ } } setMessage(sbFind.toString()); // preload list if few items if (list.size() <= 30) { t.notifyListeners(SWT.Modify, null); } return comp; }
From source file:org.eclipse.eatop.examples.graphicaleditor.depd.features.views.RequirementsLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); StyledString text = new StyledString(); if (element instanceof SafetyGoal) { SafetyGoal safetyGoal = (SafetyGoal) element; text.append(safetyGoal.getShortName() + "[" + ((EObject) safetyGoal).eClass().getName() + "]"); cell.setImage(GraphitiUi.getImageService().getPlatformImageForId(DEPDImageProvider.IMAGE_SAFETY_GOAL)); text.append(" (" + safetyGoal.getRequirement().size() + ") ", StyledString.COUNTER_STYLER); }// ww w . j a v a 2 s. com if (element instanceof QualityRequirement) { QualityRequirement qr = (QualityRequirement) element; text.append(qr.getShortName() + "[" + ((EObject) qr).eClass().getName() + "]"); cell.setImage(GraphitiUi.getImageService() .getPlatformImageForId(DEPDImageProvider.IMAGE_QUALITY_REQUIREMENT)); } List<Requirement> reqs = new ArrayList<Requirement>(); if (element instanceof Requirement && !(element instanceof QualityRequirement)) { Requirement requirement = (Requirement) element; reqs = getAllRequirementsInSatisfies(safetyGoal); if (reqs.isEmpty()) { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); } for (Requirement req : reqs) { if (req.equals(requirement)) { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN)); break; } else { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); } } text.append(requirement.getShortName() + "[" + ((EObject) requirement).eClass().getName() + "]"); cell.setImage(GraphitiUi.getImageService().getPlatformImageForId(DEPDImageProvider.IMAGE_REQUIREMENT)); } if (element instanceof Identifiable) { if (element instanceof AnalysisFunctionPrototype) { text.append(((Identifiable) element).getShortName() + "[" + ((EObject) element).eClass().getName() + "]"); cell.setImage(GraphitiUi.getImageService() .getPlatformImageForId(DEPDImageProvider.IMAGE_ANALYSIS_FUNCTION_PROTOTYPE)); } if (element instanceof DesignFunctionPrototype) { text.append(((Identifiable) element).getShortName() + "[" + ((EObject) element).eClass().getName() + "]"); cell.setImage(GraphitiUi.getImageService() .getPlatformImageForId(DEPDImageProvider.IMAGE_DESIGN_FUNCTION_PROTOTYPE)); } } cell.setText(text.toString()); cell.setStyleRanges(text.getStyleRanges()); super.update(cell); }
From source file:org.eclipse.eavp.viz.visit.VisitPlotViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the current ICEResource for * this PlotViewer./* w w w . ja v a2 s .c o m*/ * * @param inputTreeViewer * The TreeViewer that should be configured to display the * currently selected plots for a VisIt-compatible ICEResource. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { // Set up the content provider and label provider for the TreeViewer. // The input should be of the type Entry[]. Elements should be the // entries themselves. // Set the content provider, which determines how the input (an Entry[]) // should produce elements in the TreeViewer. inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { // No image descriptors or non-textual resources to dispose. return; } @Override public boolean hasChildren(Object element) { // Currently, we do not have nested elements in the tree. return false; } @Override public Object getParent(Object element) { // Currently, we do not have nested elements in the tree. return null; } @Override public Object[] getElements(Object inputElement) { Object[] elements; if (inputElement instanceof Object[]) { elements = (Object[]) inputElement; } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Currently, we do not have nested elements in the tree. return null; } }); // Set up the label provider, which determines what string is displayed // for each element in the tree. Currently, this only needs to produce // a string for each Entry. inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the Entry if possible. StyledString styledStr = new StyledString(); if (element instanceof VizEntry) { VizEntry entry = (VizEntry) element; // Get the name from the resource styledStr.append(entry.getName()); // Append the path stored as the Entry description styledStr.append(" [" + entry.getParent(), StyledString.QUALIFIER_STYLER); // Append the data type stored as the Entry parent styledStr.append("-" + entry.getDescription() + "]", StyledString.QUALIFIER_STYLER); } // If the element isn't an Entry, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.eavp.viz.VizFileViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the ResourceComponent for * this VizFileViewer./*from ww w . ja v a 2 s. c o m*/ * * @param inputTreeViewer * The TreeViewer that should be configured to display the * ICEResources in a ResourceComponent. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { return; } @Override public boolean hasChildren(Object element) { // Make sure we have a VizResource if (element instanceof IVizResource) { // Cast it to make life easier IVizResource resource = (IVizResource) element; // If this resource has a valid fileset... if (resource.getFileSet() != null) { // Then return true if it is not empty return resource.getFileSet().length != 0; // If the fileset was null, but we have children // resources... } else if (resource.getChildrenResources() != null) { // then return true if the children list is not empty return !resource.getChildrenResources().isEmpty(); } } // All else, we have no children return false; } @Override public Object getParent(Object element) { return null; } @Override public Object[] getElements(Object inputElement) { // Local Declaration Object[] elements; // Convert the element to an ArrayList (it should be an // ArrayList<ICEResource>) and then get an Object array. if (inputElement instanceof ArrayList<?>) { elements = ((ArrayList<?>) inputElement).toArray(); } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Make sure this is a VizResource if (parentElement instanceof IVizResource) { // Cast to make life easier IVizResource resource = (IVizResource) parentElement; // If we have children... if (resource.getChildrenResources() != null && !resource.getChildrenResources().isEmpty()) { // Return all Child resources return resource.getChildrenResources().toArray(); } else if (resource.getFileSet() != null && resource.getFileSet().length != 0) { // If we didn't have VizResourc children, then check // that we // have file names to return ArrayList<IVizResource> children = new ArrayList<IVizResource>(); for (String filePath : resource.getFileSet()) { File file = new File(filePath); // Try to construct an ICEResource from the File, // then add it to // the viewer. try { IVizResource childResource = new VisualizationResource(file); childResource.setHost("localhost"); children.add(childResource); } catch (IOException e) { System.err.println("AddLocalFileAction error: Failed to " + "create an ICEResource for the file at \"" + filePath + "\"."); logger.error(getClass().getName() + " Exception!", e); } } return children.toArray(); } } // Otherwise return null return null; } }); inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the VizResource if possible. StyledString styledStr = new StyledString(); if (element instanceof IVizResource) { IVizResource resource = (IVizResource) element; // Get the name from the resource styledStr.append(resource.getName()); String host = resource.getHost(); URI pathFile = resource.getPath(); String path = null; if (pathFile != null) { pathFile.getPath(); } // Get the host from the resource and append it to the tree // entry String grayed-out and enclosed in square brackets. if (host != null && !host.isEmpty()) { styledStr.append(" [" + host, StyledString.QUALIFIER_STYLER); // Include the path with the host if available if (path != null && !path.isEmpty() && !resource.isRemote()) { styledStr.append(":" + path, StyledString.QUALIFIER_STYLER); } styledStr.append("]", StyledString.QUALIFIER_STYLER); } } // If the element isn't an VizResource, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.emf.emfstore.client.ui.dialogs.BranchSelectionDialog.java
License:Open Source License
/** * Create contents of the dialog.// w w w.ja v a2 s . c om * * @param parent * parent component * @return a control */ @Override protected Control createDialogArea(Composite parent) { setHeaderTexts(); Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayout(new GridLayout(1, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); addCreationField(container); setTableViewer(new TableViewer(container, SWT.BORDER | SWT.V_SCROLL)); Table list = getTableViewer().getTable(); list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); getTableViewer().setContentProvider(ArrayContentProvider.getInstance()); getTableViewer().setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof BranchInfo) { BranchInfo branch = (BranchInfo) element; StyledString styledString = new StyledString("Branch: " + branch.getName() + " ", StyledString.createColorRegistryStyler("red", null)); styledString.append("[Version: " + branch.getHead().getIdentifier() + "]", StyledString.DECORATIONS_STYLER); cell.setText(styledString.toString()); cell.setStyleRanges(styledString.getStyleRanges()); } super.update(cell); } }); getTableViewer().setInput(getBranches()); endOfInit(); return area; }
From source file:org.eclipse.ice.viz.visit.VisitPlotViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the current ICEResource for * this PlotViewer./*w ww . j av a 2 s .c om*/ * * @param inputTreeViewer * The TreeViewer that should be configured to display the * currently selected plots for a VisIt-compatible ICEResource. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { // Set up the content provider and label provider for the TreeViewer. // The input should be of the type Entry[]. Elements should be the // entries themselves. // Set the content provider, which determines how the input (an Entry[]) // should produce elements in the TreeViewer. inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { // No image descriptors or non-textual resources to dispose. return; } @Override public boolean hasChildren(Object element) { // Currently, we do not have nested elements in the tree. return false; } @Override public Object getParent(Object element) { // Currently, we do not have nested elements in the tree. return null; } @Override public Object[] getElements(Object inputElement) { Object[] elements; if (inputElement instanceof Object[]) { elements = (Object[]) inputElement; } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Currently, we do not have nested elements in the tree. return null; } }); // Set up the label provider, which determines what string is displayed // for each element in the tree. Currently, this only needs to produce // a string for each Entry. inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the Entry if possible. StyledString styledStr = new StyledString(); if (element instanceof Entry) { Entry entry = (Entry) element; // Get the name from the resource styledStr.append(entry.getName()); // Append the path stored as the Entry description styledStr.append(" [" + entry.getParent(), StyledString.QUALIFIER_STYLER); // Append the data type stored as the Entry parent styledStr.append("-" + entry.getDescription() + "]", StyledString.QUALIFIER_STYLER); } // If the element isn't an Entry, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.ice.viz.VizFileViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the ResourceComponent for * this VizFileViewer.//from ww w .j av a2 s . c o m * * @param inputTreeViewer * The TreeViewer that should be configured to display the * ICEResources in a ResourceComponent. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { return; } @Override public boolean hasChildren(Object element) { // Make sure we have a VizResource if (element instanceof VizResource) { // Cast it to make life easier VizResource resource = (VizResource) element; // If this resource has a valid fileset... if (resource.getFileSet() != null) { // Then return true if it is not empty return resource.getFileSet().length != 0; // If the fileset was null, but we have children // resources... } else if (resource.getChildrenResources() != null) { // then return true if the children list is not empty return !resource.getChildrenResources().isEmpty(); } } // All else, we have no children return false; } @Override public Object getParent(Object element) { return null; } @Override public Object[] getElements(Object inputElement) { // Local Declaration Object[] elements; // Convert the element to an ArrayList (it should be an // ArrayList<ICEResource>) and then get an Object array. if (inputElement instanceof ArrayList<?>) { elements = ((ArrayList<?>) inputElement).toArray(); } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Make sure this is a VizResource if (parentElement instanceof VizResource) { // Cast to make life easier VizResource resource = (VizResource) parentElement; // If we have children... if (resource.getChildrenResources() != null && !resource.getChildrenResources().isEmpty()) { // Return all Child resources return resource.getChildrenResources().toArray(); } else if (resource.getFileSet() != null && resource.getFileSet().length != 0) { // If we didn't have VizResourc children, then check // that we // have file names to return return resource.getFileSet(); } } // Otherwise return null return null; } }); inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the VizResource if possible. StyledString styledStr = new StyledString(); if (element instanceof VizResource) { VizResource resource = (VizResource) element; // Get the name from the resource styledStr.append(resource.getName()); String host = resource.getHost(); String path = resource.getPath().getPath(); // Get the host from the resource and append it to the tree // entry String grayed-out and enclosed in square brackets. if (host != null && !host.isEmpty()) { styledStr.append(" [" + host, StyledString.QUALIFIER_STYLER); // Include the path with the host if available if (path != null && !path.isEmpty() && !resource.isRemote()) { styledStr.append(":" + path, StyledString.QUALIFIER_STYLER); } styledStr.append("]", StyledString.QUALIFIER_STYLER); } } // If the element isn't an VizResource, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.incquery.tooling.localsearch.ui.debugger.provider.OperationListLabelProvider.java
License:Open Source License
@Override public void update(final ViewerCell cell) { localResourceManager = new LocalResourceManager(JFaceResources.getResources(Display.getCurrent())); final SearchOperationViewerNode node = (SearchOperationViewerNode) cell.getElement(); StyledString text = new StyledString(); text.append(node.getLabelText());//www . j a v a 2 s .co m switch (node.getOperationStatus()) { case EXECUTED: cell.setImage(appliedOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { textStyle.font = localResourceManager .createFont(FontDescriptor.createFrom("Arial", 10, SWT.BOLD)); doColoring(node, textStyle); } }); break; case CURRENT: cell.setImage(currentOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { LocalResourceManager localResMan = new LocalResourceManager( JFaceResources.getResources(Display.getCurrent())); textStyle.font = localResMan .createFont(FontDescriptor.createFrom("Arial", 10, SWT.BOLD | SWT.ITALIC)); doColoring(node, textStyle); textStyle.background = localResourceManager.createColor(new RGB(200, 235, 255)); } }); break; case QUEUED: cell.setImage(notAppliedOperationImage); text.setStyle(0, text.length(), new Styler() { public void applyStyles(TextStyle textStyle) { LocalResourceManager localResMan = new LocalResourceManager( JFaceResources.getResources(Display.getCurrent())); textStyle.font = localResMan.createFont(FontDescriptor.createFrom("Arial", 10, SWT.NORMAL)); doColoring(node, textStyle); } }); break; default: throw new UnsupportedOperationException("Unknown operation status: " + node.getOperationStatus()); } cell.setText(text.toString()); cell.setStyleRanges(text.getStyleRanges()); super.update(cell); }
From source file:org.eclipse.incquery.tooling.ui.wizards.internal.ImportListLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); StyledString text = new StyledString(); if (element instanceof EPackage) { EPackage ePackage = (EPackage) element; text.append(ePackage.getNsURI()); if (ePackage.eResource().getURI().isPlatform()) { text.append(String.format(" (%s)", ePackage.eResource().getURI()), StyledString.QUALIFIER_STYLER); }/* w w w . j ava 2 s .c o m*/ cell.setImage(imageRegistry.get(IncQueryGUIPlugin.ICON_EPACKAGE)); } cell.setText(text.getString()); cell.setStyleRanges(text.getStyleRanges()); super.update(cell); }