org.eclipse.nebula.widgets.grid.GridItem Java Examples

The following examples show how to use org.eclipse.nebula.widgets.grid.GridItem. 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: GridViewerEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
    * FIXME
    * {@inheritDoc}
    */
public ViewerCell getFocusCell() {
	Grid grid = (Grid)getViewer().getControl();

	if( grid.getCellSelectionEnabled() ) {
		Point p = grid.getFocusCell();

		if( p.x >= 0 && p.y >= 0 ) {
			GridItem item = grid.getItem(p.y);
			if( item != null ) {
				ViewerRow row = getViewerRowFromItem(item);
				return row.getCell(p.x);
			}
		}
	}

	return null;
}
 
Example #2
Source File: TerminologyViewPart.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void updateUI(final String pureText, final Vector<Hashtable<String, String>> terms) {
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			List<String> temp = new ArrayList<String>();
			for (int i = 0; i < terms.size(); i++) {
				GridItem item = new GridItem(gridTable, SWT.NONE);
				item.setText(0, (i + 1) + "");
				item.setText(1, terms.get(i).get("srcWord"));
				item.setText(2, terms.get(i).get("tgtWord"));
				item.setText(3, terms.get(i).get("property") == null ? "" : terms.get(i).get("property"));
				temp.add(terms.get(i).get("srcWord"));
			}
			if (terms.size() > 0) {
				firstAction.setEnabled(true);
				gridTable.select(0);
			}
			updateStatusInfo("");
			tempEditor.highlightedTerms(getHighlightWord(pureText, temp));

		}
	});
}
 
Example #3
Source File: MatchViewerBodyMenu.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void updateEnabledState() {

			int selectionIndex = view.gridTable.getSelectionIndex();
			if (selectionIndex < 0 || selectionIndex > view.gridTable.getItemCount()) {
				setEnabled(false);
				return;
			}
			GridItem item = view.gridTable.getItem(selectionIndex);
			Object obj = item.getData("tmFuzzyInfo");
			if (obj == null) {
				setEnabled(false);
				return;
			}
			FuzzySearchResult fuzzyResult = (FuzzySearchResult) obj;
			if (fuzzyResult.getDbOp() == null) {
				setEnabled(false);
				return;
			}
			setEnabled(true);

		}
 
Example #4
Source File: MatchViewerBodyMenu.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void updateEnabledState() {
	int selectionIndex = view.gridTable.getSelectionIndex();
	if (selectionIndex < 0 || selectionIndex > view.gridTable.getItemCount()) {
		setEnabled(false);
		return;
	}
	GridItem item = view.gridTable.getItem(selectionIndex);
	Object obj = item.getData("tmFuzzyInfo");
	if (obj == null) {
		setEnabled(false);
		return;
	}
	FuzzySearchResult fuzzyResult = (FuzzySearchResult) obj;
	if (fuzzyResult.getDbOp() == null) {
		setEnabled(false);
		return;
	}
	setEnabled(true);
}
 
Example #5
Source File: GridTreeViewer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new ViewerRow at rowIndex
 * 
 * @param parent 
 * 				the parent row
 * @param style 
 * 				the style bits to use for the new row
 * @param rowIndex 
 * 				the index at which the new row should be created under the parent
 * @return ViewerRow 
 * 				the new row
 */
private ViewerRow createNewRowPart(ViewerRow parent, int style, int rowIndex) {
	if (parent == null) {
		if (rowIndex >= 0) {
			return getViewerRowFromItem(new GridItem(grid, style, rowIndex));
		}
		return getViewerRowFromItem(new GridItem(grid, style));
	}

	if (rowIndex >= 0) {
		return getViewerRowFromItem(new GridItem((GridItem) parent
				.getItem(), SWT.NONE, rowIndex));
	}

	return getViewerRowFromItem(new GridItem((GridItem) parent.getItem(),
			SWT.NONE));
}
 
Example #6
Source File: GridCopyEnable.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
void clearSelection() {
	int start = selection.x;
	int end = selection.y;
	selection.x = selection.y = caretOffset;
	selectionAnchor = -1;
	// redraw old selection, if any
	if (end - start > 0 && gridTable.getItems().length != 0) {
		if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
			GridItem item = gridTable.getItem(focusItemIndex);
			GridColumn col = gridTable.getColumn(focusColIndex);
			GridCellRenderer gcr = col.getCellRenderer();
			if (gcr != null && gcr instanceof XGridCellRenderer) {
				GC gc = new GC(gcr.getDisplay());
				layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
				gc.dispose();
			}
			if (layout == null) {
				return;
			}
		}
		Rectangle rect = layout.getBounds(start, end);
		gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
	}
}
 
Example #7
Source File: GridTreeViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a new ViewerRow at rowIndex
 * 
 * @param parent 
 * 				the parent row
 * @param style 
 * 				the style bits to use for the new row
 * @param rowIndex 
 * 				the index at which the new row should be created under the parent
 * @return ViewerRow 
 * 				the new row
 */
private ViewerRow createNewRowPart(ViewerRow parent, int style, int rowIndex) {
	if (parent == null) {
		if (rowIndex >= 0) {
			return getViewerRowFromItem(new GridItem(grid, style, rowIndex));
		}
		return getViewerRowFromItem(new GridItem(grid, style));
	}

	if (rowIndex >= 0) {
		return getViewerRowFromItem(new GridItem((GridItem) parent
				.getItem(), SWT.NONE, rowIndex));
	}

	return getViewerRowFromItem(new GridItem((GridItem) parent.getItem(),
			SWT.NONE));
}
 
Example #8
Source File: GridTreeViewer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new ViewerRow at rowIndex
 * 
 * @param parent 
 * 				the parent row
 * @param style 
 * 				the style bits to use for the new row
 * @param rowIndex 
 * 				the index at which the new row should be created under the parent
 * @return ViewerRow 
 * 				the new row
 */
private ViewerRow createNewRowPart(ViewerRow parent, int style, int rowIndex) {
	if (parent == null) {
		if (rowIndex >= 0) {
			return getViewerRowFromItem(new GridItem(grid, style, rowIndex));
		}
		return getViewerRowFromItem(new GridItem(grid, style));
	}

	if (rowIndex >= 0) {
		return getViewerRowFromItem(new GridItem((GridItem) parent
				.getItem(), SWT.NONE, rowIndex));
	}

	return getViewerRowFromItem(new GridItem((GridItem) parent.getItem(),
			SWT.NONE));
}
 
Example #9
Source File: GridViewerEditor.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	Grid grid = ((Grid)getViewer().getControl());

	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		
		if( selectionFollowsEditor ) {
			grid.setCellSelection(new Point(focusCell.getColumnIndex(),((GridItem)focusCell.getItem()).getRowIndex()));
		}
	}
			
	grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
	grid.showItem((GridItem) focusCell.getItem()); 
}
 
Example #10
Source File: GridViewerEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
	Grid grid = ((Grid)getViewer().getControl());

	if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
		grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
		grid.setFocusItem((GridItem) focusCell.getItem());
		
		if( selectionFollowsEditor ) {
			grid.setCellSelection(new Point(focusCell.getColumnIndex(),grid.indexOf((GridItem)focusCell.getItem())));
		}
	}
			
	grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
	grid.showItem((GridItem) focusCell.getItem()); 
}
 
Example #11
Source File: MatchViewerBodyMenu.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
	int selectionIndex = view.gridTable.getSelectionIndex();
	if (selectionIndex < 0 || selectionIndex > view.gridTable.getItemCount()) {
		return;
	}
	GridItem item = view.gridTable.getItem(selectionIndex);
	Object obj = item.getData("tmFuzzyInfo");
	if (obj == null) {
		return;
	}
	FuzzySearchResult fuzzyResult = (FuzzySearchResult) obj;

	TmMatchEditDialog dlg = new TmMatchEditDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), fuzzyResult);
	if (dlg.open() == Window.OK) {
		try {
			view.tmMatcher.updateFuzzResult(fuzzyResult);
			view.reLoadMatches(view.editor, view.rowIndex);
		} catch (Exception e) {
			MessageDialog.openError(view.getSite().getShell(),
					Messages.getString("view.MatchViewerBodyMenu.erorr.title"),
					Messages.getString("view.MatchViewerBodyMenu.error.editError") + e.getMessage());
			logger.error("Updaste TM matche Error",e);
		}
	}
}
 
Example #12
Source File: GridViewerRow.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private ViewerRow getRowBelow() {
	int index = item.getRowIndex() + 1;

	if (index < item.getParent().getItemCount()) {
		GridItem tmp = item.getParent().getItem(index);
		// Maybe this is a dummy item!!

		if (tmp != null && !tmp.isDisposed() && tmp.isVisible() && tmp.getData() != null) {
			return new GridViewerRow(tmp);
		}
	}

	return null;
}
 
Example #13
Source File: GridSnippet8.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());

	final Grid grid = new Grid(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	grid.setHeaderVisible(true);
	grid.setAutoHeight(true);
	grid.setAutoWidth(true);

	GridColumn column1 = new GridColumn(grid, SWT.NONE);
	column1.setText("Column 1");
	column1.setWidth(150);
	column1.setWordWrap(true);

	GridColumn column2 = new GridColumn(grid, SWT.NONE);
	column2.setText("Column 2");
	column2.setWidth(200);
	column2.setWordWrap(true);

	GridItem item1 = new GridItem(grid, SWT.NONE);
	item1.setText(0, "Item 1, Column 0: " + LONG_TEXT);
	item1.setText(1, "Item 1, Column 1: " + LONG_TEXT);

	GridItem item2 = new GridItem(grid, SWT.NONE);
	item2.setText("Item 2, Columns 0-1: " + LONG_TEXT);
	item2.setColumnSpan(0, 1);

	GridItem item3 = new GridItem(grid, SWT.NONE);
	item3.setText(0, "Item 3, Column 0: " + MEDIUM_TEXT);
	item3.setText(1, "Item 3, Column 1: " + MEDIUM_TEXT);

	shell.setSize(400, 400);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example #14
Source File: GridTreeViewer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected ViewerRow getViewerRowFromItem(Widget item) {
	if (cachedRow == null) {
		cachedRow = new GridViewerRow((GridItem) item);
	} else {
		cachedRow.setItem((GridItem) item);
	}

	return cachedRow;
}
 
Example #15
Source File: GridViewerSnippetWithAdaptedDataVisualizer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Color getBackground(GridItem gridItem, int columnIndex) {
	if ((models[gridItem.getRowIndex()]).counter % 2 == 0) {
		return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
	}
	return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
}
 
Example #16
Source File: TermViewerBodyMenu.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
void updateActionsState() {
	IProject curentProject = getCurentProject();
	GridItem selectItem = getSelectItem();
	if (curentProject != null && null != selectItem) {
		setEnabled(true);
	} else {
		setEnabled(false);
	}
}
 
Example #17
Source File: GridTableViewer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected ViewerRow getViewerRowFromItem(Widget item) {
	if (cachedRow == null) {
		cachedRow = new GridViewerRow((GridItem) item);
	} else {
		cachedRow.setItem((GridItem) item);
	}

	return cachedRow;
}
 
Example #18
Source File: GridSnippet4.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout(new FillLayout());

    Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    grid.setHeaderVisible(true);
    GridColumn column = new GridColumn(grid,SWT.NONE);
    column.setText("Column 1");
    column.setWidth(100);
    GridColumnGroup columnGroup = new GridColumnGroup(grid,SWT.NONE);
    columnGroup.setText("Column Group");
    GridColumn column2 = new GridColumn(columnGroup,SWT.NONE);
    column2.setText("Column 2");
    column2.setWidth(60);
    GridColumn column3 = new GridColumn(columnGroup,SWT.NONE);
    column3.setText("Column 3");
    column3.setWidth(60);
    GridItem item1 = new GridItem(grid,SWT.NONE);
    item1.setText("First Item");
    item1.setText(1,"abc");
    GridItem item2 = new GridItem(grid,SWT.NONE);
    item2.setText("Second Item");
    item2.setText(2,"def");
    GridItem item3 = new GridItem(grid,SWT.NONE);
    item3.setText("Third Item");
    item3.setText(1,"xyz");
    
    shell.setSize(250,250);
    shell.open ();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
 
Example #19
Source File: GridSnippet5.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout(new FillLayout());

    Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    grid.setHeaderVisible(true);
    GridColumn column = new GridColumn(grid,SWT.NONE);
    column.setText("Column 1");
    column.setWidth(100);
    GridColumnGroup columnGroup = new GridColumnGroup(grid,SWT.TOGGLE);
    columnGroup.setText("Column Group");
    GridColumn column2 = new GridColumn(columnGroup,SWT.NONE);
    column2.setText("Column 2");
    column2.setWidth(60);
    GridColumn column3 = new GridColumn(columnGroup,SWT.NONE);
    column3.setText("Column 3");
    column3.setWidth(60);
    column3.setSummary(false);
    column3.setDetail(true);
    GridItem item1 = new GridItem(grid,SWT.NONE);
    item1.setText("First Item");
    item1.setText(1,"abc");
    GridItem item2 = new GridItem(grid,SWT.NONE);
    item2.setText("Second Item");
    item2.setText(2,"def");
    GridItem item3 = new GridItem(grid,SWT.NONE);
    item3.setText("Third Item");
    item3.setText(1,"xyz");
    
    shell.setSize(250,250);
    shell.open ();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
 
Example #20
Source File: GridSnippet3.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout(new FillLayout());

    Grid grid = new Grid(shell,SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    grid.setHeaderVisible(true);
    GridColumn column = new GridColumn(grid,SWT.NONE);
    column.setText("Column 1");
    column.setWidth(100);
    GridColumn column2 = new GridColumn(grid,SWT.CHECK | SWT.CENTER);
    column2.setText("Column 2");
    column2.setWidth(100);
    GridItem item1 = new GridItem(grid,SWT.NONE);
    item1.setText("First Item");
    item1.setChecked(1,true);
    GridItem item2 = new GridItem(grid,SWT.NONE);
    item2.setText("Second Item");
    GridItem item3 = new GridItem(grid,SWT.NONE);
    item3.setText("Third Item");
    
    shell.setSize(250,250);
    shell.open ();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
 
Example #21
Source File: GridViewerRow.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private ViewerRow getRowBelow() {
	int index = item.getParent().indexOf(item) + 1;

	if( index < item.getParent().getItemCount() ) {
		GridItem tmp = item.getParent().getItem(index);
		if( tmp != null ) {
			return new GridViewerRow(tmp);
		}
	}

	return null;
}
 
Example #22
Source File: GridViewerColumn.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void setEditingSupport(EditingSupport editingSupport)
{
	currentEditingSupport = editingSupport;
	if (!getColumn().isVisible()) {
		return;
	}

    if (editingSupport instanceof CheckEditingSupport)
    {
        if (checkEditingSupport == null)
        {
            final int colIndex = getColumn().getParent().indexOf(getColumn());

            getColumn().getParent().addListener(SWT.Selection, new Listener()
            {
                public void handleEvent(Event event)
                {
                    if (event.detail == SWT.CHECK && event.index == colIndex)
                    {
                        GridItem item = (GridItem)event.item;
                        Object element = item.getData();
                        checkEditingSupport.setValue(element, new Boolean(item.getChecked(colIndex)));
                    }
                }
            });
        }
        checkEditingSupport = (CheckEditingSupport)editingSupport;
    }
    else
    {
        super.setEditingSupport(editingSupport);
    }
}
 
Example #23
Source File: GridTreeViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void setSelection(List items) {
	Item[] current = getSelection(getGrid());

	// Don't bother resetting the same selection
	if (isSameSelection(items, current)) {
		return;
	}

	GridItem[] newItems = new GridItem[items.size()];
	items.toArray(newItems);
	getGrid().setSelection(newItems);
	getGrid().showSelection();
}
 
Example #24
Source File: GridTableViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void doSetSelection(Item[] items) {
    GridItem[] items2 = new GridItem[items.length];
    for (int i = 0; i < items.length; i++) {
        items2[i] = (GridItem) items[i];
    }
    grid.setSelection(items2);
    grid.showSelection();
}
 
Example #25
Source File: GridTableViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void doResetItem(Item item) {
    GridItem gridItem = (GridItem) item;
    int columnCount = Math.max(1, grid.getColumnCount());
    for (int i = 0; i < columnCount; i++) {
        gridItem.setText(i, ""); //$NON-NLS-1$
        gridItem.setImage(null);
    }
}
 
Example #26
Source File: GridTableViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
    super.doUpdateItem(widget, element, fullMap);
    updateRowHeader(widget);
    if (autoPreferredHeight && !widget.isDisposed())
        ((GridItem) widget).pack();
}
 
Example #27
Source File: GridViewerEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private ViewerRow getViewerRowFromItem(GridItem item) {
	if( getViewer() instanceof GridTableViewer ) {
		return ((GridTableViewer)getViewer()).getViewerRowFromItem(item);
	} else {
		return ((GridTreeViewer)getViewer()).getViewerRowFromItem(item);
	}
}
 
Example #28
Source File: GridTreeViewer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void doUpdateItem(final Item item, Object element) {
	super.doUpdateItem(item, element);
	updateRowHeader(item);
	if(autoPreferredHeight && !item.isDisposed())
		((GridItem)item).pack();
}
 
Example #29
Source File: GridTreeViewer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected ViewerRow getViewerRowFromItem(Widget item) {
	if (cachedRow == null) {
		cachedRow = new GridViewerRow((GridItem) item);
	} else {
		cachedRow.setItem((GridItem) item);
	}

	return cachedRow;
}
 
Example #30
Source File: GridTableViewer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void doSetSelection(Item[] items) {
	GridItem[] items2 = new GridItem[items.length];
	for (int i = 0; i < items.length; i++) {
		items2[i] = (GridItem) items[i];
	}
	grid.setSelection(items2);
	grid.showSelection();
}