Java Code Examples for org.eclipse.jface.viewers.TableViewer#add()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#add() . 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: TypeScriptSearchTableContentProvider.java    From typescript.java with MIT License 6 votes vote down vote up
public void elementsChanged(Object[] updatedElements) {
	TableViewer viewer = getViewer();
	int elementLimit = getElementLimit();
	boolean tableLimited = elementLimit != -1;
	for (int i = 0; i < updatedElements.length; i++) {
		if (fResult.getMatchCount(updatedElements[i]) > 0) {
			if (viewer.testFindItem(updatedElements[i]) != null)
				viewer.update(updatedElements[i], null);
			else {
				if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
					viewer.add(updatedElements[i]);
			}
		} else
			viewer.remove(updatedElements[i]);
	}
}
 
Example 2
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 6 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent) {
	parent.setLayout(new GridLayout(1, false));

	txtInput = new Text(parent, SWT.BORDER);
	txtInput.setMessage("Enter text to mark part as dirty");
	txtInput.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			dirty.setDirty(true);
		}
	});
	txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	tableViewer = new TableViewer(parent);

	tableViewer.add("Sample item 1");
	tableViewer.add("Sample item 2");
	tableViewer.add("Sample item 3");
	tableViewer.add("Sample item 4");
	tableViewer.add("Sample item 5");
	tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
 
Example 3
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 6 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent) {
	parent.setLayout(new GridLayout(1, false));

	txtInput = new Text(parent, SWT.BORDER);
	txtInput.setMessage("Enter text to mark part as dirty");
	txtInput.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			dirty.setDirty(true);
		}
	});
	txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	tableViewer = new TableViewer(parent);

	tableViewer.add("Sample item 1");
	tableViewer.add("Sample item 2");
	tableViewer.add("Sample item 3");
	tableViewer.add("Sample item 4");
	tableViewer.add("Sample item 5");
	tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
 
Example 4
Source File: FileTableContentProvider.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void elementsChanged(Object[] updatedElements) {
    TableViewer viewer = getViewer();
    int elementLimit = getElementLimit();
    boolean tableLimited = elementLimit != -1;
    for (int i = 0; i < updatedElements.length; i++) {
        if (fResult.getMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                viewer.update(updatedElements[i], null);
            else {
                if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
                    viewer.add(updatedElements[i]);
            }
        } else
            viewer.remove(updatedElements[i]);
    }
}
 
Example 5
Source File: UnDefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleUnDefineAddButton(TableViewer tableViewer) {
  final Shell shell = tableViewer.getControl().getShell();
  AddCmakeUndefineDialog dlg = new AddCmakeUndefineDialog(shell, null);
  if (dlg.open() == Dialog.OK) {
    CmakeUnDefine cmakeDefine = dlg.getCmakeUndefine();
    @SuppressWarnings("unchecked")
    ArrayList<CmakeUnDefine> undefines = (ArrayList<CmakeUnDefine>) tableViewer
        .getInput();
    undefines.add(cmakeDefine);
    tableViewer.add(cmakeDefine); // updates the display
  }
}
 
Example 6
Source File: DefinesViewer.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void handleDefineAddButton(TableViewer tableViewer) {
  final Shell shell = tableViewer.getControl().getShell();
  AddCmakeDefineDialog dlg = new AddCmakeDefineDialog(shell, cfgd, null);
  if (dlg.open() == Dialog.OK) {
    CmakeDefine cmakeDefine = dlg.getCmakeDefine();
    @SuppressWarnings("unchecked")
    ArrayList<CmakeDefine> defines = (ArrayList<CmakeDefine>) tableViewer
        .getInput();
    defines.add(cmakeDefine);
    tableViewer.add(cmakeDefine); // updates the display
  }
}
 
Example 7
Source File: JavaSearchTableContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void elementsChanged(Object[] updatedElements) {
	if (getSearchResult() == null)
		return;

	int addLimit= getAddLimit();

	TableViewer viewer= (TableViewer) getPage().getViewer();
	Set<Object> updated= new HashSet<Object>();
	Set<Object> added= new HashSet<Object>();
	Set<Object> removed= new HashSet<Object>();
	for (int i= 0; i < updatedElements.length; i++) {
		if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) {
			if (viewer.testFindItem(updatedElements[i]) != null)
				updated.add(updatedElements[i]);
			else {
				if (addLimit > 0) {
					added.add(updatedElements[i]);
					addLimit--;
				}
			}
		} else {
			removed.add(updatedElements[i]);
		}
	}

	viewer.add(added.toArray());
	viewer.update(updated.toArray(), new String[] { SearchLabelProvider.PROPERTY_MATCH_COUNT });
	viewer.remove(removed.toArray());
}
 
Example 8
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent) {
	parent.setLayout(new GridLayout(1, false));

	txtInput = new Text(parent, SWT.BORDER);
	txtInput.setMessage("Enter text to mark part as dirty");
	txtInput.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			dirty.setDirty(true);
		}
	});
	txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	tableViewer = new TableViewer(parent);

	tableViewer.add("Sample item 1");
	tableViewer.add("Sample item 2");
	tableViewer.add("Sample item 3");
	tableViewer.add("Sample item 4");
	tableViewer.add("Sample item 5");
	tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
	tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
		
		@Override
		public void selectionChanged(SelectionChangedEvent event) {
			selectionService.setSelection("Hello");
		}
	});
}
 
Example 9
Source File: SamplePart.java    From e4Preferences with Eclipse Public License 1.0 5 votes vote down vote up
@PostConstruct
public void createComposite(Composite parent, @Preference(value = "prefColor") String colorKey)
{
	parent.setLayout(new GridLayout(1, false));

	txtInput = new Text(parent, SWT.BORDER);
	txtInput.setMessage("Enter text to mark part as dirty");
	txtInput.addModifyListener(new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e)
		{
			dirty.setDirty(true);
		}
	});
	txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

	tableViewer = new TableViewer(parent);

	tableViewer.add("Sample item 1");
	tableViewer.add("Sample item 2");
	tableViewer.add("Sample item 3");
	tableViewer.add("Sample item 4");
	tableViewer.add("Sample item 5");
	tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
	
	reactOnPrefColorChange(colorKey);
}
 
Example 10
Source File: PageLoaderStrategyHelper.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * This method loads the paginated list by using the given page loader
 * {@link IPageLoader} and information about pagination from the given
 * controller {@link PageableController}. After loading paginated list
 * returned in a pagination structure {@link PageResult}, this method :
 * 
 * <ul>
 * <li>update the total elements of the given controller
 * {@link PageableController}</li>
 * <li>refresh the given {@link Viewer} by replacing data with the new
 * paginated list.</li>
 * </ul>
 * 
 * @param controller
 *            the controller to use to load paginated list and update the
 *            total elements.
 * @param viewer
 *            the viewer to refresh with new paginated list.
 * @param pageLoader
 *            the page loader used to load paginated list.
 * @pageContentProvider the page content provider to retrieves total
 *                      elements+paginated list from the page result
 *                      structure returned by the pageLoader.
 * @param handler
 *            the page loader handler to observe before/after page loading
 *            process. If null no observation is done.
 */
public static void loadPageAndAddItems(final PageableController controller,
		final TableViewer viewer, final IPageLoader<?> pageLoader,
		final IPageContentProvider pageContentProvider,
		final IPageLoaderHandler<PageableController> handler) {
	Object page = loadPageAndUpdateTotalElements(controller, pageLoader,
			pageContentProvider, handler);
	if (page != null) {
		List<?> content = pageContentProvider.getPaginatedList(page);
		if (content != null && !content.isEmpty()) {
			viewer.add(content.toArray());
			int count = viewer.getTable().getItemCount();
			if (count > 0) {
				TableItem item = viewer.getTable().getItem(count - 1);
				item.setData(LazyItemsSelectionListener.LAST_ITEM_LOADED,
						true);
			}
		}
	}
}