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

The following examples show how to use org.eclipse.swt.widgets.Table#getItem() . 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: ModulaContentAssistant.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void selectProposal(ICompletionProposal proposal) {
	try{
		Object fProposalPopup = ReflectionUtils.getField(this.getClass(), "fProposalPopup", this, true);
		Object fProposalTable = ReflectionUtils.getField(fProposalPopup.getClass(), "fProposalTable", fProposalPopup, true);
		if (fProposalTable instanceof Table) {
			Table table = (Table) fProposalTable;
			int i = 0; 
			for (;i < table.getItemCount(); i++) {
				TableItem item = table.getItem(i);
				if (Objects.equals(item.getData(), proposal)) {
					break;
				}
			}
			if (i < table.getItemCount()) {
				Method selectMethod = ReflectionUtils.findMethod(fProposalPopup.getClass(), "selectProposal", int.class, boolean.class);
				ReflectionUtils.invokeMethod(selectMethod, fProposalPopup, i, false);
			}
		}
	}
	catch(AssertionError e) {
	}
}
 
Example 2
Source File: ExportToTsvUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Export content of a table to TSV file
 * @param table
 *              the table to export
 * @param stream
 *              the output stream
 */
public static void exportTableToTsv(Table table, @Nullable OutputStream stream) {
    if (table == null || stream == null) {
        return;
    }
    try (PrintWriter pw = new PrintWriter(stream)) {
        int size = table.getItemCount();
        List<String> columns = new ArrayList<>();
        for (int i = 0; i < table.getColumnCount(); i++) {
            TableColumn column = table.getColumn(i);
            if (column == null) {
                return;
            }
            String columnName = String.valueOf(column.getText());
            if (columnName.isEmpty() && i == table.getColumnCount() - 1) {
                // Linux GTK2 undocumented feature
                break;
            }
            columns.add(columnName);
        }
        pw.println(Joiner.on('\t').join(columns));
        for (int i = 0; i < size; i++) {
            TableItem item = table.getItem(i);
            if (item == null) {
                continue;
            }
            List<String> data = new ArrayList<>();
            for (int col = 0; col < columns.size(); col++) {
                data.add(String.valueOf(item.getText(col)));
            }
            pw.println(Joiner.on('\t').join(data));
        }
    }
}
 
Example 3
Source File: AdvancedSettingsComponent.java    From aem-eclipse-developer-tools with Apache License 2.0 5 votes vote down vote up
public void updateTable() {
    Table table = propertiesViewer.getTable();
    table.setItemCount(properties.size());
    int i = 0;
    for (String key : properties.keySet()) {
    	RequiredPropertyWrapper property = properties.get(key);
    	TableItem item = table.getItem(i++);
        item.setText(0, property.getKey());
       	item.setText(1, property.getValue() != null ? property.getValue() : "");
        item.setText(2, property.getDefaultValue() != null ? property.getDefaultValue() : "");
        item.setData(item);
    }

}
 
Example 4
Source File: FeatureEnvy.java    From JDeodorant with MIT License 5 votes vote down vote up
protected boolean shouldCreateToolTip(Event event) {
	Table table = tableViewer.getTable();
	Point coords = new Point(event.x, event.y);
	TableItem item = table.getItem(coords);
	if(item != null) {
		List<CandidateRefactoring> prerequisiteRefactorings = getPrerequisiteRefactorings((CandidateRefactoring)item.getData());
		if(!prerequisiteRefactorings.isEmpty())
			return true;
	}
	return false;
}
 
Example 5
Source File: FeatureEnvy.java    From JDeodorant with MIT License 5 votes vote down vote up
private void saveResults() {
	FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE);
	fd.setText("Save Results");
	String[] filterExt = { "*.txt" };
	fd.setFilterExtensions(filterExt);
	String selected = fd.open();
	if(selected != null) {
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(selected));
			Table table = tableViewer.getTable();
			TableColumn[] columns = table.getColumns();
			for(int i=0; i<columns.length; i++) {
				if(i == columns.length-1)
					out.write(columns[i].getText());
				else
					out.write(columns[i].getText() + "\t");
			}
			out.newLine();
			for(int i=0; i<table.getItemCount(); i++) {
				TableItem tableItem = table.getItem(i);
				for(int j=0; j<table.getColumnCount(); j++) {
					if(j == table.getColumnCount()-1)
						out.write(tableItem.getText(j));
					else
						out.write(tableItem.getText(j) + "\t");
				}
				out.newLine();
			}
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
Example 6
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private ItemPkg getCell(Event event, Table table) {
	ItemPkg result = null;
	TableItem item = table.getItem(new Point(event.x,event.y));

	if (item != null) {
		for (int i = 0; i < table.getColumnCount(); i++) {
			if (item.getBounds(i).contains(event.x, event.y)) {
				result = new ItemPkg(item,i);
				break;
			}
		}
	}
	return result;
}
 
Example 7
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private ItemPkg getCell(MouseEvent event, Table table) {
	ItemPkg result = null;
	TableItem item = table.getItem(new Point(event.x,event.y));

	if (item != null) {
		for (int i = 0; i < table.getColumnCount(); i++) {
			if (item.getBounds(i).contains(event.x, event.y)) {
				result = new ItemPkg(item,i);
				break;
			}
		}
	}
	return result;
}
 
Example 8
Source File: ViewAttributeList.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Update
 * @param attribute
 */
private void updateSelectedAttribute(String attribute) {
    if (model != null && model.getInputConfig() != null && model.getInputConfig().getInput() != null) {
        Table table = this.table.getViewer().getTable();
        for (int i=0; i < table.getItemCount(); i++) {
            TableItem item = table.getItem(i);
            if (item.getData().equals(attribute)) {
                table.select(i);
                break;
            }
        }
    }
}
 
Example 9
Source File: Tables.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Get the table item where the given event occurred. Returns null if the event
 * occurred in the empty table area.
 */
public static TableItem getItem(TableViewer viewer, MouseEvent event) {
	if (viewer == null || event == null)
		return null;
	Table table = viewer.getTable();
	if (table == null)
		return null;
	return table.getItem(new Point(event.x, event.y));
}
 
Example 10
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 11
Source File: FeatureEnvy.java    From JDeodorant with MIT License 4 votes vote down vote up
protected Composite createToolTipContentArea(Event event, Composite parent) {
	Composite comp = new Composite(parent,SWT.NONE);
	GridLayout gl = new GridLayout(1,false);
	gl.marginBottom=0;
	gl.marginTop=0;
	gl.marginHeight=0;
	gl.marginWidth=0;
	gl.marginLeft=0;
	gl.marginRight=0;
	gl.verticalSpacing=1;
	comp.setLayout(gl);

	Composite topArea = new Composite(comp,SWT.NONE);
	GridData data = new GridData(SWT.FILL,SWT.FILL,true,false);
	data.widthHint=200;
	topArea.setLayoutData(data);
	topArea.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

	gl = new GridLayout(1,false);
	gl.marginBottom=2;
	gl.marginTop=2;
	gl.marginHeight=0;
	gl.marginWidth=0;
	gl.marginLeft=5;
	gl.marginRight=2;

	topArea.setLayout(gl);

	Label label = new Label(topArea,SWT.NONE);
	label.setText("APPLY FIRST");
	label.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
	label.setFont(JFaceResources.getFontRegistry().get(HEADER_FONT));
	//label.setForeground(JFaceResources.getColorRegistry().get(HEADER_FG_COLOR));
	label.setLayoutData(new GridData(GridData.FILL_BOTH));

	Table table = tableViewer.getTable();
	Point coords = new Point(event.x, event.y);
	TableItem item = table.getItem(coords);
	if(item != null) {
		List<CandidateRefactoring> prerequisiteRefactorings = getPrerequisiteRefactorings((CandidateRefactoring)item.getData());
		if(!prerequisiteRefactorings.isEmpty()) {
			final CandidateRefactoring firstPrerequisite = prerequisiteRefactorings.get(0);
			Composite comp2 = new Composite(comp,SWT.NONE);
			comp2.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
			FillLayout layout = new FillLayout();
			layout.marginWidth=5;
			comp2.setLayout(layout);
			Link link = new Link(comp2,SWT.NONE);
			link.setText("<a>" + firstPrerequisite.getSourceEntity() + "\n->" + firstPrerequisite.getTarget() + "</a>");
			link.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
			link.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					setSelectedLine(firstPrerequisite);
				}
			});
			comp2.setLayoutData(new GridData(GridData.FILL_BOTH));
		}
	}
	return comp;
}