Java Code Examples for org.eclipse.swt.widgets.Table#setSelection()

The following examples show how to use org.eclipse.swt.widgets.Table#setSelection() . 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: OrderableFieldDialogImpl.java    From jenerate with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Move the current selection in the field list down.
 */
private void moveSelectionDown() {
    Table builderTable = fieldViewer.getTable();
    int indices[] = builderTable.getSelectionIndices();
    if (indices.length < 1) {
        return;
    }
    int newSelection[] = new int[indices.length];
    int max = builderTable.getItemCount() - 1;
    for (int i = indices.length - 1; i >= 0; i--) {
        int index = indices[i];
        if (index < max) {
            move(builderTable.getItem(index), index + 1);
            newSelection[i] = index + 1;
        }
    }
    builderTable.setSelection(newSelection);
}
 
Example 2
Source File: TemplateSelectDialog.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the template options in the passed list (swt)
 */
private void fillTemplateOptions(TemplatePersistenceData[] templateData, Table list) {
    nameToTemplateData = new TreeMap<String, TemplatePersistenceData>();

    for (TemplatePersistenceData data : templateData) {
        if (PyContextType.PY_MODULES_CONTEXT_TYPE.equals(data.getTemplate().getContextTypeId())) {
            String name = data.getTemplate().getName();
            nameToTemplateData.put(name, data);
        }
    }
    ArrayList<String> lst = new ArrayList<String>(nameToTemplateData.keySet());
    for (String string : lst) {
        new TableItem(list, SWT.NONE).setText(string);
    }
    list.setSelection(0);
}
 
Example 3
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 4
Source File: TableCombo.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * creates the popup shell.
 *
 * @param selectionIndex
 */
void createPopup(final int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null) {
		table.setFont(font);
	}
	if (foreground != null) {
		table.setForeground(foreground);
	}
	if (background != null) {
		table.setBackground(background);
	}

	// Add popup listeners
	final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (final int popupEvent : popupEvents) {
		popup.addListener(popupEvent, listener);
	}

	// add table listeners
	final int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
			SWT.Dispose };
	for (final int tableEvent : tableEvents) {
		table.addListener(tableEvent, listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 5
Source File: ColumnBrowserWidget.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Update the content of the widget
 */
void updateContent() {
	if (columns == null) {
		return;
	}

	for (int i = 0; i < columns.size(); i++) {

		final Table table = columns.get(i);
		final int index = table.getSelectionIndex();
		table.removeAll();
		if (table.getData() == null) {
			continue;
		}
		for (final ColumnItem c : ((ColumnItem) table.getData()).getItems()) {
			final TableItem item = new TableItem(table, SWT.NONE);
			item.setData(c);
			if (c.getText() != null) {
				item.setText(c.getText());
			}
			if (c.getImage() != null) {
				item.setImage(c.getImage());
			}
		}
		table.setSelection(index);
	}
}
 
Example 6
Source File: OrderableFieldDialogImpl.java    From jenerate with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Move the current selection in the field list up.
 */
private void moveSelectionUp() {
    Table builderTable = fieldViewer.getTable();
    int indices[] = builderTable.getSelectionIndices();
    int newSelection[] = new int[indices.length];
    for (int i = 0; i < indices.length; i++) {
        int index = indices[i];
        if (index > 0) {
            move(builderTable.getItem(index), index - 1);
            newSelection[i] = index - 1;
        }
    }
    builderTable.setSelection(newSelection);
}
 
Example 7
Source File: FeatureEnvy.java    From JDeodorant with MIT License 5 votes vote down vote up
public void setSelectedLine(final CandidateRefactoring candidateRefactoring) {
	Table table = tableViewer.getTable();
	for(int i=0; i<table.getItemCount(); i++) {
		Object tableElement = tableViewer.getElementAt(i);
		CandidateRefactoring candidate = (CandidateRefactoring)tableElement;
		if(candidate.equals(candidateRefactoring)) {
			table.setSelection(i);
			break;
		}
	}
}
 
Example 8
Source File: TableCombo.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
    // create shell and table
    popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

    // create table
    table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

    if (font != null)
        table.setFont(font);
    if (foreground != null)
        table.setForeground(foreground);
    if (background != null)
        table.setBackground(background);

    // Add popup listeners
    int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
    for (int i = 0; i < popupEvents.length; i++) {
        popup.addListener(popupEvents[i], listener);
    }

    // add table listeners
    int[] tableEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn,
            SWT.Dispose };
    for (int i = 0; i < tableEvents.length; i++) {
        table.addListener(tableEvents[i], listener);
    }

    // set the selection
    if (selectionIndex != -1) {
        table.setSelection(selectionIndex);
    }
}
 
Example 9
Source File: AggregateSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Handle add to flow.
 */
private void handleAddToFlow() {
  String node = filesTable.getSelection()[0].getText(1);
  addNodeToFlow(node);
  getTable().setSelection(-1);
  enable();
  Table flowList = editor.getAggregatePage().getFlowSection().getFlowList();
  flowList.setSelection(flowList.getItemCount() - 1);
  editor.getAggregatePage().getFlowSection().enable();
  flowList.setFocus();
}
 
Example 10
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Swap table items.
 *
 * @param itemBelow the item below
 * @param newSelection the new selection
 */
public static void swapTableItems(TableItem itemBelow, int newSelection) {
  Table parent = itemBelow.getParent();
  int i = getIndex(itemBelow);
  TableItem itemAbove = parent.getItems()[i - 1];
  TableItem newItemAbove = new TableItem(parent, SWT.NONE, i - 1);
  copyTableItem(newItemAbove, itemBelow);
  TableItem newItemBelow = new TableItem(parent, SWT.NONE, i);
  copyTableItem(newItemBelow, itemAbove);
  itemAbove.dispose();
  itemBelow.dispose();
  parent.setSelection(newSelection);
}
 
Example 11
Source File: ContactSelectionDialog.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void okPressed(){
	
	Object bKSel = getBezugsKontaktSelection();
	if (bKSel instanceof Kontakt) {
		selection = bKSel;
	} else if (bKSel instanceof BezugsKontakt) {
		BezugsKontakt bezugsKontakt = (BezugsKontakt) bKSel;
		Kontakt kontakt = Kontakt.load(bezugsKontakt.get("otherID"));
		if (kontakt.exists()) {
			selection = kontakt;
		}
	} else {
		if (selection == null) {
			Object[] sel = commonViewer.getSelection();
			if ((sel != null) && (sel.length > 0)) {
				selection = sel[0];
			} else {
				Table tbl = (Table) commonViewer.getViewerWidget().getControl();
				tbl.setSelection(0);
				if (commonViewer.getSelection().length > 0) {
					selection = commonViewer.getSelection()[0];
				}
			}
		}
	}
	vc.getContentProvider().stopListening();
	commonViewer.removeDoubleClickListener(this);
	super.okPressed();
}
 
Example 12
Source File: KontaktSelektor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void okPressed(){
	
	Object bKSel = getBezugsKontaktSelection();
	if (bKSel instanceof Kontakt) {
		selection = bKSel;
	} else if (bKSel instanceof BezugsKontakt) {
		BezugsKontakt bezugsKontakt = (BezugsKontakt) bKSel;
		Kontakt kontakt = Kontakt.load(bezugsKontakt.get("otherID"));
		if (kontakt.exists()) {
			selection = kontakt;
		}
	} else {
		if (selection == null) {
			Object[] sel = cv.getSelection();
			if ((sel != null) && (sel.length > 0)) {
				selection = sel[0];
			} else {
				Table tbl = (Table) cv.getViewerWidget().getControl();
				tbl.setSelection(0);
				if (cv.getSelection().length > 0) {
					selection = cv.getSelection()[0];
				}
			}
		}
	}
	vc.getContentProvider().stopListening();
	cv.removeDoubleClickListener(this);
	super.okPressed();
}
 
Example 13
Source File: TableCombo.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 14
Source File: TableCombo.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * creates the popup shell.
 * @param selectionIndex
 */
void createPopup(int selectionIndex) {
	// create shell and table
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);

	// set style
	int style = getStyle();
	int tableStyle = SWT.SINGLE | SWT.V_SCROLL;
	if ((style & SWT.FLAT) != 0)
		tableStyle |= SWT.FLAT;
	if ((style & SWT.RIGHT_TO_LEFT) != 0)
		tableStyle |= SWT.RIGHT_TO_LEFT;
	if ((style & SWT.LEFT_TO_RIGHT) != 0)
		tableStyle |= SWT.LEFT_TO_RIGHT;

	// create table
	table = new Table(popup, SWT.SINGLE | SWT.FULL_SELECTION);

	if (font != null)
		table.setFont(font);
	if (foreground != null)
		table.setForeground(foreground);
	if (background != null)
		table.setBackground(background);

	// Add popup listeners
	int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate, SWT.Help };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}

	// add table listeners
	int[] tableEvents = { SWT.MouseMove, SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp,
			SWT.FocusIn, SWT.Dispose };
	for (int i = 0; i < tableEvents.length; i++) {
		table.addListener(tableEvents[i], listener);
	}

	// set the selection
	if (selectionIndex != -1) {
		table.setSelection(selectionIndex);
	}
}
 
Example 15
Source File: OfflineActionTarget.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void verifyKey(VerifyEvent event) {

    if (!event.doit)
        return;

    if (event.character == 0) {

        switch (event.keyCode) {

            case SWT.ARROW_DOWN:
                //special case: 
                //if there's a key dialog with a table shown, set its focus when down is pressed
                synchronized (lock) {
                    KeyAssistDialog tempKeyAssistDialog = this.keyAssistDialog;
                    if (tempKeyAssistDialog != null) {
                        Table completionsTable = this.keyAssistDialog.getCompletionsTable();
                        if (completionsTable != null && !completionsTable.isDisposed()) {
                            completionsTable.setFocus();
                            completionsTable.setSelection(0);
                            event.doit = false;
                            break;
                        }
                    }
                }
                // ALT, CTRL, ARROW_LEFT, ARROW_RIGHT == leave
            case SWT.ARROW_LEFT:
            case SWT.ARROW_RIGHT:
            case SWT.HOME:
            case SWT.END:
            case SWT.PAGE_DOWN:
            case SWT.PAGE_UP:
            case SWT.ARROW_UP:
                leave();
                break;

        }

        // event.character != 0
    } else {

        switch (event.character) {

        // ESC = quit
            case 0x1B:
                leave();
                event.doit = false;
                break;

            //CR = exec and quit
            case 0x0D:
                boolean executed = doExec();
                event.doit = false;
                if (!executed) {
                    return; //we don't want to update the status
                }
                break;

            // backspace    and delete
            case 0x08:
            case 0x7F:
                removeLastCharSearch();
                event.doit = false;
                break;

            default:
                if (event.stateMask == 0 || event.stateMask == SWT.SHIFT || event.stateMask == (SWT.ALT | SWT.CTRL)) { // SWT.ALT | SWT.CTRL covers AltGr (see bug 43049)
                    event.doit = false;
                    if (addCharSearch(event.character)) {
                        //ok, triggered some automatic action (does not need enter)
                        executed = doExec();
                        if (!executed) {
                            return; //we don't want to update the status
                        }

                    }
                }
                break;
        }
    }
    updateStatus();
}