List of usage examples for org.eclipse.jface.viewers ViewerCell setText
public void setText(String text)
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.TagLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); int index = cell.getColumnIndex(); switch (index) { case 0:/*w w w . j ava 2 s. c o m*/ String title = getText(element, index); cell.setText(title); break; case 1: // Image image = getImage(index); // cell.setImage(image); break; default: break; } super.update(cell); }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.VulnerabilityLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); if (element instanceof Trace) { int index = cell.getColumnIndex(); switch (index) { case 0:// w w w . jav a2s .co m case 3: Image image = getImage(element, index); cell.setImage(image); break; case 1: String title = getText(element, index); if (title.startsWith(UNLICENSED_PREFIX)) { StyledString text = new StyledString(); StyleRange range = new StyleRange(0, UNLICENSED_PREFIX.length(), Constants.UNLICENSED_COLOR, null); text.append(title, StyledString.DECORATIONS_STYLER); StyleRange[] ranges = { range }; cell.setStyleRanges(ranges); } cell.setText(title); break; case 2: String appName = ((Trace) element).getApplication().getName(); cell.setText(appName); break; default: break; } if (index == 0) { } } super.update(cell); }
From source file:com.dubture.symfony.ui.views.ServiceLabelProvider.java
License:Open Source License
@Override public void update(ViewerCell cell) { Object element = cell.getElement(); Styler style = null;/*from www .jav a 2 s. c o m*/ if (element instanceof IProject) { IProject project = (IProject) element; StyledString styledString = new StyledString(project.getName(), style); cell.setText(styledString.toString()); cell.setImage(PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_PROJECT)); } else if (element instanceof Service) { Service service = (Service) element; String name = service.getClassName() != null ? service.getClassName() : service.getId(); StyledString styledString = new StyledString(name, style); String decoration = MessageFormat.format(" [{0}]", new Object[] { service.getId() }); //$NON-NLS-1$ styledString.append(decoration, StyledString.DECORATIONS_STYLER); cell.setText(styledString.toString()); cell.setStyleRanges(styledString.getStyleRanges()); if (service.isPublic()) { cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PUBLIC)); } else { cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_SERVICE_PRIVATE)); } } else if (element instanceof Bundle) { Bundle bundle = (Bundle) element; StyledString styledString = new StyledString(bundle.getElementName(), style); cell.setText(styledString.toString()); cell.setImage(SymfonyPluginImages.get(SymfonyPluginImages.IMG_OBJS_BUNDLE2)); } }
From source file:com.freescale.deadlockpreventer.agent.StatisticsDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { parent.setLayout(new GridLayout(2, false)); viewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); layoutData.horizontalSpan = 2;//from w ww. j a v a 2s. co m viewer.getTable().setLayoutData(layoutData); viewer.setContentProvider(new ViewContentProvider()); ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE); viewer.setInput(locks); IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class); service.addFocusTracker(viewer.getTable(), StatisticsDialog.class.getPackage().getName() + ".table"); viewer.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Row element = (Row) cell.getElement(); if (cell.getColumnIndex() == 0) cell.setText(element.id); if (cell.getColumnIndex() == 1) cell.setText(Integer.toString(element.folllowersCount)); if (cell.getColumnIndex() == 2) cell.setText(Integer.toString(element.precedentsCount)); if (cell.getColumnIndex() == 3) cell.setText(element.location); } public String getToolTipText(Object element) { Row row = (Row) element; ILock[] locks = transaction.getLocks(row.index, row.index + 1); CharArrayWriter writer = new CharArrayWriter(); Logger.dumpLockInformation(locks, writer); return writer.toString(); } public Point getToolTipShift(Object object) { return new Point(5, 5); } public int getToolTipDisplayDelayTime(Object object) { return 2000; } public int getToolTipTimeDisplayed(Object object) { return 5000; } }); createTableViewerColumn("Lock", 200, 0); createTableViewerColumn("Followers", 70, 1); createTableViewerColumn("Precedents", 70, 2); createTableViewerColumn("Location", 250, 3); viewer.getTable().setHeaderVisible(true); viewer.getTable().setLinesVisible(true); comparator = new TableViewerComparator(); viewer.setComparator(comparator); Button button = new Button(parent, SWT.PUSH); button.setText("Export..."); layoutData = new GridData(SWT.BEGINNING, SWT.TOP, false, false); layoutData.widthHint = 80; button.setLayoutData(layoutData); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StatisticsUtil.export(transaction); } }); Label label = new Label(parent, 0); label.setText("Total locks: " + locks.length); label.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false)); return super.createDialogArea(parent); }
From source file:com.freescale.deadlockpreventer.agent.StatisticsDialog.java
License:Open Source License
private TableViewerColumn createTableViewerColumn(String title, int bound, final int colNumber) { final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); final TableColumn column = viewerColumn.getColumn(); column.setText(title);/* w ww . j a va2s. c om*/ column.setWidth(bound); column.setResizable(true); column.setMoveable(true); column.addSelectionListener(getSelectionAdapter(column, colNumber)); viewerColumn.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { Row element = (Row) cell.getElement(); switch (colNumber) { case 0: cell.setText(element.id); break; case 1: cell.setText(Integer.toString(element.folllowersCount)); break; case 2: cell.setText(Integer.toString(element.precedentsCount)); break; case 3: cell.setText(element.location); break; } } public String getToolTipText(Object element) { Row row = (Row) element; ILock[] locks = transaction.getLocks(row.index, row.index + 1); CharArrayWriter writer = new CharArrayWriter(); try { for (String stack : locks[0].getStackTrace()) { writer.write(stack + "\n"); } } catch (IOException e) { } return writer.toString(); } }); return viewerColumn; }
From source file:com.google.gapid.widgets.MeasuringViewLabelProvider.java
License:Apache License
@Override public void update(ViewerCell cell) { // Adjusted from the DelegatingStyledCellLabelProvider implementation. StyledString styledString = format(cell.getItem(), cell.getElement(), LinkableStyledString.ignoring(theme)) .getString();/*from w w w . j a v a 2 s. co m*/ String newText = styledString.toString(); StyleRange[] oldStyleRanges = cell.getStyleRanges(); StyleRange[] newStyleRanges = styledString.getStyleRanges(); if (!Arrays.equals(oldStyleRanges, newStyleRanges)) { cell.setStyleRanges(newStyleRanges); if (cell.getText().equals(newText)) { cell.setText(""); } } Color bgcolor = getBackgroundColor(cell.getElement()); if (bgcolor != null) { cell.setBackground(bgcolor); } cell.setImage(getImage(cell.getElement())); cell.setText(newText); }
From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.rdb.table.TadpoleTableComposite.java
License:Open Source License
private void createWidget(final CTabFolder tabFolderObject) { CTabItem tbtmTable = new CTabItem(tabFolderObject, SWT.NONE); tbtmTable.setText("Tables"); //$NON-NLS-1$ Composite compositeTables = new Composite(tabFolderObject, SWT.NONE); tbtmTable.setControl(compositeTables); GridLayout gl_compositeTables = new GridLayout(1, false); gl_compositeTables.verticalSpacing = 2; gl_compositeTables.horizontalSpacing = 2; gl_compositeTables.marginHeight = 2; gl_compositeTables.marginWidth = 2;/* ww w .j av a 2s . c om*/ compositeTables.setLayout(gl_compositeTables); compositeTables.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); SashForm sashForm = new SashForm(compositeTables, SWT.NONE); sashForm.setOrientation(SWT.VERTICAL); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tableListViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION); tableListViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (PublicTadpoleDefine.YES_NO.NO.toString().equals(userDB.getIs_showtables())) return; IStructuredSelection is = (IStructuredSelection) event.getSelection(); if (null != is) { TableDAO tableDAO = (TableDAO) is.getFirstElement(); String strSQL = GenerateDDLScriptUtils.genTableScript(userDB, tableDAO, showTableColumns); if (StringUtils.isNotEmpty(strSQL)) { FindEditorAndWriteQueryUtil.run(userDB, strSQL, PublicTadpoleDefine.DB_ACTION.TABLES); } } } }); tableListViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (PublicTadpoleDefine.YES_NO.NO.toString().equals(userDB.getIs_showtables())) return; // ?? ?? . try { IStructuredSelection is = (IStructuredSelection) event.getSelection(); Object tableDAO = is.getFirstElement(); if (tableDAO != null) { TableDAO table = (TableDAO) tableDAO; if (selectTableName.equals(table.getName())) return; selectTableName = table.getName(); showTableColumns = TadpoleObjectQuery.makeShowTableColumns(userDB, table); } else { showTableColumns = null; selectTableName = ""; } tableColumnViewer.setInput(showTableColumns); tableColumnComparator = new TableColumnComparator(); tableColumnViewer.setSorter(tableColumnComparator); tableColumnViewer.refresh(); TableUtil.packTable(tableColumnViewer.getTable()); } catch (Exception e) { logger.error("get table column", e); //$NON-NLS-1$ // initialize table columns showTableColumns.clear(); tableColumnViewer.setInput(showTableColumns); tableColumnComparator = new TableColumnComparator(); tableColumnViewer.setSorter(tableColumnComparator); tableColumnViewer.refresh(); TableUtil.packTable(tableColumnViewer.getTable()); // show error message Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError(tabFolderObject.getShell(), "Error", e.getMessage(), //$NON-NLS-1$ errStatus); } } }); Table tableTableList = tableListViewer.getTable(); tableTableList.setLinesVisible(true); tableTableList.setHeaderVisible(true); // sorter tableComparator = new TableComparator(); tableListViewer.setSorter(tableComparator); tableComparator.setColumn(0); // auto table layout AutoResizeTableLayout layoutColumnLayout = new AutoResizeTableLayout(tableListViewer.getTable()); TableViewerColumn tvColName = new TableViewerColumn(tableListViewer, SWT.NONE); TableColumn tbName = tvColName.getColumn(); tbName.setWidth(170); tbName.setText("Name"); //$NON-NLS-1$ tbName.addSelectionListener(getSelectionAdapter(tableListViewer, tableComparator, tbName, 0)); tvColName.setLabelProvider(new ColumnLabelProvider() { @Override public Image getImage(Object element) { return ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/objectExplorer/tables.png"); //$NON-NLS-1$ } @Override public String getText(Object element) { TableDAO table = (TableDAO) element; return table.getName(); } }); tvColName.setEditingSupport(new TableCommentEditorSupport(tableListViewer, userDB, 0)); layoutColumnLayout.addColumnData(new ColumnWeightData(170)); // table column tooltip ColumnViewerToolTipSupport.enableFor(tableListViewer); CellLabelProvider clpTable = new CellLabelProvider() { public String getToolTipText(Object element) { TableDAO table = (TableDAO) element; return table.getComment(); } public Point getToolTipShift(Object object) { return new Point(5, 5); } public int getToolTipDisplayDelayTime(Object object) { return 100; } public int getToolTipTimeDisplayed(Object object) { return 5000; } public void update(ViewerCell cell) { TableDAO table = (TableDAO) cell.getElement(); cell.setText(table.getComment()); } }; TableViewerColumn tvTableComment = new TableViewerColumn(tableListViewer, SWT.NONE); TableColumn tbComment = tvTableComment.getColumn(); tbComment.setWidth(200); tbComment.setText("Comment"); //$NON-NLS-1$ tbComment.addSelectionListener(getSelectionAdapter(tableListViewer, tableComparator, tbComment, 1)); tvTableComment.setLabelProvider(clpTable); tvTableComment.setEditingSupport(new TableCommentEditorSupport(tableListViewer, userDB, 1)); layoutColumnLayout.addColumnData(new ColumnWeightData(200)); tableListViewer.getTable().setLayout(layoutColumnLayout); tableListViewer.setContentProvider(new ArrayContentProvider()); tableListViewer.setInput(showTables); // dnd Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() }; tableListViewer.addDragSupport(DND_OPERATIONS, transferTypes, new TableDragListener(userDB, tableListViewer)); // filter tableFilter = new TableFilter(); tableListViewer.addFilter(tableFilter); createTableMenu(); // columns tableColumnViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); tableColumnViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection is = (IStructuredSelection) event.getSelection(); if (null != is) { TableColumnDAO tableDAO = (TableColumnDAO) is.getFirstElement(); FindEditorAndWriteQueryUtil.runAtPosition(StringUtils.trim(tableDAO.getField())); } } }); Table tableTableColumn = tableColumnViewer.getTable(); tableTableColumn.setHeaderVisible(true); tableTableColumn.setLinesVisible(true); tableColumnComparator = new TableColumnComparator(); tableColumnViewer.setSorter(tableColumnComparator); createTableColumne(tableColumnViewer); tableColumnViewer.setContentProvider(new ArrayContentProvider()); tableColumnViewer.setLabelProvider(new TableColumnLabelprovider()); createTableColumnMenu(); sashForm.setWeights(new int[] { 1, 1 }); }
From source file:com.hydra.project.myplugin_nebula.xviewer.XViewer.java
License:Open Source License
/** * Refresh only single column using normal label provider mechanism. This can be called after normal loading and * after columns compute their input in the background. *//*from w w w. ja v a2s .com*/ public void refreshColumn(String columnId) { Pair<XViewerColumn, Integer> column = getCustomizeMgr().getColumnNumFromXViewerColumn(columnId); IBaseLabelProvider baseLabelProvider = getLabelProvider(); if (baseLabelProvider instanceof XViewerLabelProvider) { XViewerLabelProvider labelProvider = (XViewerLabelProvider) baseLabelProvider; TreeItem[] items = getTree().getItems(); for (TreeItem item : items) { ViewerRow viewerRow = getViewerRowFromItem(item); if (viewerRow != null) { try { ViewerCell cell = viewerRow.getCell(column.getSecond()); String value = null; try { value = labelProvider.getColumnText(item.getData(), column.getSecond()); } catch (Exception ex) { value = String.format("Exception getting value from column [%s][%s]", column.getFirst().getId(), ex.getLocalizedMessage()); } if (value != null) { cell.setText(value); } } catch (NullPointerException ex) { // do nothing } } } } }
From source file:com.hydra.project.myplugin_nebula.xviewer.XViewerStyledTextLabelProvider.java
License:Open Source License
@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); // if (cell.getText().equals(newText)) { // // make sure there will be a refresh from a change // cell.setText(""); //$NON-NLS-1$ // } }//from w w w. ja v a 2s .c o m 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. }
From source file:com.jaspersoft.studio.property.dataset.dialog.DataPreviewTable.java
License:Open Source License
private void updateTableLayout() { if (composite.isVisible()) { // Remove all table items if any wtable.removeAll();/*from w ww.j a v a 2s . c o m*/ tviewer.setInput(null); // Dispose old columns if any for (TableColumn col : wtable.getColumns()) { col.dispose(); } TableColumnLayout tColLayout = new TableColumnLayout(); tableContainer.setLayout(tColLayout); List<JRDesignField> fields = previewInfoProvider.getFieldsForPreview(); if (fields.size() > 0) { for (JRDesignField f : fields) { TableViewerColumn tvc = new TableViewerColumn(tviewer, SWT.NONE); tvc.getColumn().setText(f.getName()); tvc.setLabelProvider(new ColumnLabelProvider()); tColLayout.setColumnData(tvc.getColumn(), new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true)); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(ViewerCell cell) { DataPreviewBean element = (DataPreviewBean) cell.getElement(); Object value = element.getValue(cell.getColumnIndex()); if (value != null) { cell.setText(value.toString()); } else { cell.setText(""); //$NON-NLS-1$ } } }); } } tableContainer.layout(); } }