Java Code Examples for org.eclipse.swt.widgets.TableItem#getData()

The following examples show how to use org.eclipse.swt.widgets.TableItem#getData() . 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: AbstractGeneratorConfigurationBlock.java    From sarl with Apache License 2.0 6 votes vote down vote up
private void refreshItem(final TableItem item) {
	final TableItemData data = (TableItemData) item.getData();
	item.setText(1, data.getSourceFolder());
	final String outputDirectory = getOutputDirectory(item);
	if ("".equals(outputDirectory)) { //$NON-NLS-1$
		item.setForeground(2, Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
		item.setText(2, getValue(data.getDefaultOutputDirectoryKey()));
	} else {
		item.setForeground(2, null);
		item.setText(2, outputDirectory);
	}
	if (isIgnored(item)) {
		item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
	} else {
		item.setForeground(null);
	}
}
 
Example 2
Source File: CrosstabFilterConditionBuilder.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void modify( Object element, String property, Object value )
{
	if ( Arrays.asList( columns ).indexOf( property ) != 2 )
	{
		return;
	}
	TableItem item = (TableItem) element;
	MemberValueHandle memberValue = (MemberValueHandle) item.getData( );
	try
	{
		( memberValue ).setValue( (String) value );
	}
	catch ( SemanticException e )
	{
		logger.log( Level.SEVERE, e.getMessage( ), e );
	}

	dynamicViewer.refresh( );
}
 
Example 3
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void mouseDoubleClick(final MouseEvent event) {
    if (event.button != 1) {
        return;
    }
    // Identify the selected row
    final Point point = new Point(event.x, event.y);
    final TableItem item = fTable.getItem(point);
    if (item != null) {
        final Rectangle imageBounds = item.getImageBounds(0);
        imageBounds.width = BOOKMARK_IMAGE.getBounds().width;
        if (imageBounds.contains(point)) {
            final Long rank = (Long) item.getData(Key.RANK);
            if (rank != null) {
                toggleBookmark(rank);
            }
        }
    }
}
 
Example 4
Source File: BuilderConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void refreshItem(final TableItem item) {
	TableItemData data = (TableItemData) item.getData();
	item.setText(1, data.getSourceFolder());
	String outputDirectory = getOutputDirectory(item);
	if ("".equals(outputDirectory)) {
		item.setForeground(2, Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
		item.setText(2, getValue(data.getDefaultOutputDirectoryKey()));
	} else {
		item.setForeground(2, null);
		item.setText(2, outputDirectory);
	}
	if (isIgnored(item)) {
		item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
	} else {
		item.setForeground(null);
	}
}
 
Example 5
Source File: EventViewTable.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public List<DecoratedEvent> selectedEvents ()
{
    if ( this.tableViewer.getTable ().getSelectionCount () == 0 )
    {
        return new ArrayList<DecoratedEvent> ();
    }
    final ArrayList<DecoratedEvent> result = new ArrayList<DecoratedEvent> ();
    for ( final TableItem row : this.tableViewer.getTable ().getSelection () )
    {
        if ( row.getData () instanceof DecoratedEvent )
        {
            result.add ( (DecoratedEvent)row.getData () );
        }
    }
    return result;
}
 
Example 6
Source File: ManifestServicesDialog.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean performDialogOperation(IProgressMonitor progressMonitor) {
    // OK was pressed
    // Record the ticked Services
    _serviceList.clear();
    TableItem[] items = _serviceTable.getTable().getItems(); 
    for (TableItem item : items) {
        if (item.getChecked() == true) {
            if (item.getData() instanceof CloudService) {
                CloudService cs = (CloudService) item.getData();
                _serviceList.add(new TableEntry(cs.getName()));
            }
        }
    }
    return true;
}
 
Example 7
Source File: JdbcDriverManagerDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * refresh jar
 *
 */
private void refreshJar( )
{
	for ( int i = 0; i < jarViewer.getTable( ).getItemCount( ); i++ )
	{
		TableItem ti = jarViewer.getTable( ).getItem( i );

		Object element = ti.getData( );

		String c0 = "", c1 = "", c2 = ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

		if ( element instanceof Map.Entry )
		{
			Map.Entry entry = (Map.Entry) element;
			JarFile jarInfo = (JarFile) entry.getValue( );
			c0 = jarInfo.getState( );
			c1 = (String) entry.getKey( );
			c2 = jarInfo.getFilePath( );
		}

		ti.setText( 0, c0 );
		ti.setText( 1, c1 );
		ti.setText( 2, c2 );
	}

}
 
Example 8
Source File: PickOverrideKeysAndParmName.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Fill parameter candidates.
 */
private void fillParameterCandidates() {
  paramsUI.setRedraw(false);
  paramsUI.removeAll();
  TableItem selectedItem = keysUI.getSelection()[0];

  Map.Entry entry = (Map.Entry) selectedItem.getData();
  String keyName = (String) entry.getKey();
  // support CasConsumers also
  // support Flow Controllers too
  // and skip remote service descriptors

  ResourceSpecifier rs = (ResourceSpecifier) entry.getValue();
  if (rs instanceof AnalysisEngineDescription || rs instanceof CasConsumerDescription
          || rs instanceof FlowControllerDescription) {
    ConfigurationParameterDeclarations delegateCpd = ((ResourceCreationSpecifier) rs)
            .getMetaData().getConfigurationParameterDeclarations();
    
    addSelectedParms(delegateCpd, keyName);

  }
  if (0 < paramsUI.getItemCount()) {
    paramsUI.setSelection(0);
  }
  paramsUI.setRedraw(true);
}
 
Example 9
Source File: QuickMenuDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isSeparator(TableItem item)
{
	Object obj = item.getData(IS_SEPARATOR);
	if (obj instanceof Boolean)
	{
		return (Boolean) obj;
	}
	return false;
}
 
Example 10
Source File: TableCellModifier.java    From Eclipse-Environment-Variables with MIT License 5 votes vote down vote up
@Override public void modify(final Object element, final String property, final Object value) {
	final TableItem item = (TableItem) element;
	final TableLine line = (TableLine) item.getData();
	if (property.equals(keyProperty)) {
		line.setVariable((String) value);
	} else if (property.equals(valueProperty)) {
		line.setValue((String) value);
	}
	tableViewer.update(new Object[] { line }, new String[] { property });
	tableViewer.refresh(line);
}
 
Example 11
Source File: IgnorePage.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected Set<String> gatherIgnoredFactories ()
{
    final Set<String> result = new HashSet<String> ();
    for ( final TableItem item : this.factoriesViewer.getTable ().getItems () )
    {
        if ( item.getChecked () )
        {
            final String data = (String)item.getData ();
            result.add ( data );
        }
    }
    return result;
}
 
Example 12
Source File: Dashboard.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
private void selectMergeUnits(IMergeUnit[] mergeUnitsToSelect) {
	final Table table = view.getTableViewer().getTable();
	TableItem[] tableItems = table.getItems();

	ArrayList<TableItem> tableItemsToSelect = new ArrayList<>();

	for (TableItem tableItem : tableItems) {
		Object data = tableItem.getData();

		if (data != null && data instanceof IMergeUnit) {
			IMergeUnit mergeUnit = (IMergeUnit) data;

			for (IMergeUnit mergeUnitToSelect : mergeUnitsToSelect) {
				if (mergeUnit.compareTo(mergeUnitToSelect) == 0) {
					tableItemsToSelect.add(tableItem);
					break;
				}
			}
		} else {
			String message = String.format("Error while reading selection.Unexpected tableItem data. data=[%s]", //$NON-NLS-1$
					data);
			throw LogUtil.throwing(new MergeDataException(message));
		}
	}

	table.setSelection(tableItemsToSelect.toArray(new TableItem[tableItemsToSelect.size()]));
}
 
Example 13
Source File: SWTTable.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("unchecked")
public UITableItem<T> getItem(int index) {
	if( index >= 0 && index < this.getItemCount()) {
		TableItem tableItem = this.getControl().getItem(index);
		if( tableItem != null ) {
			return (UITableItem<T>) tableItem.getData();
		}
	}
	return null;
}
 
Example 14
Source File: SWTTable.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TableItem getTableItem(UITableItem<T> item) {
	if( item != null ) {
		TableItem[] tableItems = this.getControl().getItems();
		for(TableItem tableItem : tableItems) {
			if( tableItem.getData() != null && tableItem.getData().equals(item) ) {
				return tableItem;
			}
		}
	}
	return null;
}
 
Example 15
Source File: ColumnBrowserWidget.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Selects an item in the receiver. If the item was already selected, it remains
 * selected.
 *
 * @param item the item to be selected
 *
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the item is null</li>
 *                <li>ERROR_INVALID_ARGUMENT - if the item has been disposed
 *                </li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 */
public void select(final ColumnItem item) {

	final List<ColumnItem> items = new ArrayList<ColumnItem>();
	findElement(item, items);
	Collections.reverse(items);
	if (items.isEmpty()) {
		return;
	}

	clear(false);
	for (int i = 3; i < items.size(); i++) {
		createTable();
	}
	for (int i = 0; i < items.size() - 1; i++) {
		columns.get(i + 1).setData(items.get(i));
	}
	updateContent();

	for (int i = 0; i < columns.size() - 1; i++) {
		final ColumnItem nextItem = (ColumnItem) columns.get(i + 1).getData();
		for (final TableItem tableItem : columns.get(i).getItems()) {
			if (tableItem.getData() != null && tableItem.getData().equals(nextItem)) {
				tableItem.getParent().setSelection(tableItem);
			}
		}
	}

	composite.pack();
	this.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	columns.get(columns.size() - 1).forceFocus();
}
 
Example 16
Source File: ServiceMetadataCustomPropertiesTable.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public void modify(Object element, String property, Object value) {

            int columnIndex = tableViewer.getColumnNames().indexOf(property);

            TableItem item = (TableItem) element;
            CustomProperty customProperty = (CustomProperty) item.getData();

            if (0 == columnIndex) {
                customProperty.setName(((String) value).trim());
            } else if (1 == columnIndex) {
                customProperty.setValue(((String) value).trim());
            }
            tableViewer.properties.updateProperty(customProperty);
        }
 
Example 17
Source File: NewCodewindProjectPage.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public ProjectTemplateInfo getProjectTemplateInfo() {
	if (selectionTable != null) {
		int index = selectionTable.getSelectionIndex();
		if (index >= 0) {
			TableItem item = selectionTable.getItem(index);
			return (ProjectTemplateInfo)item.getData();
		}
	}
	return null;
}
 
Example 18
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Add a bookmark to this event table.
 *
 * @param bookmarksFile
 *            The file to use for the bookmarks
 */
public void addBookmark(final IFile bookmarksFile) {
    fBookmarksFile = bookmarksFile;
    final TableItem[] selection = fTable.getSelection();
    if (selection.length > 0) {
        final TableItem tableItem = selection[0];
        if (tableItem.getData(Key.RANK) != null) {
            final StringBuffer defaultMessage = new StringBuffer();
            for (int i : fTable.getColumnOrder()) {
                TableColumn column = fTable.getColumns()[i];
                // Omit the margin column and hidden columns
                if (isVisibleEventColumn(column)) {
                    if (defaultMessage.length() > 0) {
                        defaultMessage.append(", "); //$NON-NLS-1$
                    }
                    defaultMessage.append(tableItem.getText(i));
                }
            }
            final AddBookmarkDialog dialog = new AddBookmarkDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), defaultMessage.toString());
            if (dialog.open() == Window.OK) {
                final String message = dialog.getValue();
                try {
                    final Long rank = (Long) tableItem.getData(Key.RANK);
                    final String location = NLS.bind(Messages.TmfMarker_LocationRank, rank.toString());
                    final ITmfTimestamp timestamp = (ITmfTimestamp) tableItem.getData(Key.TIMESTAMP);
                    final long[] id = new long[1];
                    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            final IMarker bookmark = bookmarksFile.createMarker(IMarker.BOOKMARK);
                            bookmark.setAttribute(IMarker.MESSAGE, message.toString());
                            bookmark.setAttribute(IMarker.LOCATION, location);
                            bookmark.setAttribute(ITmfMarker.MARKER_RANK, rank.toString());
                            bookmark.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(timestamp.toNanos()));
                            bookmark.setAttribute(ITmfMarker.MARKER_COLOR, dialog.getColorValue().toString());
                            id[0] = bookmark.getId();
                        }
                    }, null);
                    fBookmarksMap.put(rank, id[0]);
                    fTable.refresh();
                } catch (final CoreException e) {
                    TraceUtils.displayErrorMsg(e);
                }
            }
        }
    }

}
 
Example 19
Source File: ProjectBuildPathPropertyPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handle table selection. In case it's a single selection, enable/disable the 'Up' and 'Down' buttons according to
 * the selection. We only allow up and down for checked items.
 */
private void handleTableSelection()
{
	ISelection selection = tableViewer.getSelection();
	if (selection instanceof StructuredSelection)
	{
		StructuredSelection structuredSelection = (StructuredSelection) selection;
		Table table = tableViewer.getTable();
		if (structuredSelection.size() == 1 && table.getItemCount() > 1)
		{
			int selectionIndex = table.getSelectionIndex();
			TableItem item = table.getItem(selectionIndex);
			IBuildPathEntry data = (IBuildPathEntry) item.getData();
			if (item.getChecked())
			{
				upButton.setEnabled(selectionIndex != 0);
				downButton.setEnabled(selectionIndex < table.getItemCount() - 1
						&& selectionIndex < tableViewer.getCheckedElements().length - 1);
				if (!selectedEntries.contains(data))
				{
					selectedEntries.add(data);
					tableViewer.refresh();
				}
			}
			else
			{
				if (selectedEntries.contains(data))
				{
					selectedEntries.remove(data);
					tableViewer.refresh();
				}
				upButton.setEnabled(false);
				downButton.setEnabled(false);
			}
		}
		else
		{
			upButton.setEnabled(false);
			downButton.setEnabled(false);
		}
	}
}
 
Example 20
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void handleEvent(Event event) {
    TableItem item = (TableItem) event.item;
    List<?> styleRanges = (List<?>) item.getData(Key.STYLE_RANGES);

    GC gc = event.gc;
    Color background = item.getBackground(event.index);
    /*
     * Paint the background if it is not the default system color. In
     * Windows, if you let the widget draw the background, it will not
     * show the item's background color if the item is selected or hot.
     * If there are no style ranges and the item background is the
     * default system color, we do not want to paint it or otherwise we
     * would override the platform theme (e.g. alternating colors).
     */
    if (styleRanges != null || !background.equals(item.getParent().getBackground())) {
        // we will paint the table item's background
        event.detail &= ~SWT.BACKGROUND;

        // paint the item's default background
        gc.setBackground(background);
        gc.fillRectangle(event.x, event.y, event.width, event.height);
    }

    /*
     * We will paint the table item's foreground. In Windows, if you
     * paint the background but let the widget draw the foreground, it
     * will override your background, unless the item is selected or
     * hot.
     */
    event.detail &= ~SWT.FOREGROUND;

    // paint the highlighted background for all style ranges
    if (styleRanges != null) {
        Rectangle textBounds = item.getTextBounds(event.index);
        String text = item.getText(event.index);
        for (Object o : styleRanges) {
            if (o instanceof StyleRange) {
                StyleRange styleRange = (StyleRange) o;
                if (styleRange.data.equals(event.index)) {
                    int startIndex = styleRange.start;
                    int endIndex = startIndex + styleRange.length;
                    int startX = gc.textExtent(text.substring(0, startIndex)).x;
                    int endX = gc.textExtent(text.substring(0, endIndex)).x;
                    gc.setBackground(styleRange.background);
                    gc.fillRectangle(textBounds.x + startX, textBounds.y, (endX - startX), textBounds.height);
                }
            }
        }
    }
}