List of usage examples for org.eclipse.jface.viewers TableViewer getTable
public Table getTable()
From source file:net.karlmartens.ui.widget.GridChooser.java
License:Apache License
private static Rectangle getBounds(TableViewer viewer, GridChooserItem item, int index) { for (TableItem tableItem : viewer.getTable().getItems()) { if (tableItem.getData() == item) { final Rectangle parentBounds = viewer.getTable().getBounds(); final Rectangle childBounds = tableItem.getBounds(index); return new Rectangle(parentBounds.x + childBounds.x, parentBounds.y + childBounds.y, childBounds.width, childBounds.height); }//from w ww .j a v a 2s .c o m } throw new IllegalArgumentException(); }
From source file:net.karlmartens.ui.widget.GridChooser.java
License:Apache License
private static Rectangle getImageBounds(TableViewer viewer, GridChooserItem item, int index) { for (TableItem tableItem : viewer.getTable().getItems()) { if (tableItem.getData() == item) { final Rectangle parentBounds = viewer.getTable().getBounds(); final Rectangle childBounds = tableItem.getImageBounds(index); return new Rectangle(parentBounds.x + childBounds.x, parentBounds.y + childBounds.y, childBounds.width, childBounds.height); }// w w w.ja v a 2 s .c o m } throw new IllegalArgumentException(); }
From source file:net.lopezbobeda.rap.examples.mail.views.MainView.java
License:Open Source License
public MainView(final Composite shell) { registerImages();/*from w w w .ja va 2s . c o m*/ final Composite parent = new SashForm(shell, SWT.HORIZONTAL | SWT.FILL); GridData theCompositeGridData = new GridData(); theCompositeGridData.grabExcessHorizontalSpace = true; theCompositeGridData.grabExcessVerticalSpace = true; theCompositeGridData.horizontalAlignment = SWT.FILL; theCompositeGridData.verticalAlignment = SWT.FILL; parent.setLayoutData(theCompositeGridData); // GridLayout layout = new GridLayout(2, false); // parent.setLayout(layout); final TreeView label = new TreeView(parent); GridData labelGridData = new GridData(); // labelGridData.verticalSpan = 2; labelGridData.grabExcessVerticalSpace = true; labelGridData.verticalAlignment = SWT.FILL; label.getViewer().getTree().setLayoutData(labelGridData); final Composite rightView = new Composite(parent, SWT.NONE); GridLayout rightViewLayout = new GridLayout(1, false); rightView.setLayout(rightViewLayout); TableViewer viewer = new TableViewer(rightView, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.RESIZE); createColumns(viewer); final Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; Email[] emails = new Email[] { new Email("edmundo@lopezbobeda.net", "jean.val.jean@miserable.fr", "Urgent!!", "Message 1"), new Email("diego.de.la.vega@lopezbobeda.net", "jean.val.jean@miserable.fr", "Plus Urgent!!", "Message 2") }; final Label placeHolder = new Label(rightView, SWT.NONE); placeHolder.setText("No message selected"); table.setLayoutData(gridData); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { Composite mailView = null; @Override public void selectionChanged(SelectionChangedEvent event) { if (!placeHolder.isDisposed()) { placeHolder.dispose(); } if (mailView != null) { mailView.dispose(); } IStructuredSelection selection = (IStructuredSelection) event.getSelection(); MessageView mv = new MessageView(rightView, (Email) selection.getFirstElement()); mailView = mv.getView(); rightView.layout(); } }); viewer.setInput(emails); }
From source file:net.openchrom.chromatogram.msd.processor.supplier.massshiftdetector.ui.editingsupport.ScanMarkerCheckBoxEditingSupport.java
License:Open Source License
public ScanMarkerCheckBoxEditingSupport(TableViewer tableViewer) { super(tableViewer); this.tableViewer = tableViewer; cellEditor = new CheckboxCellEditor(tableViewer.getTable()); }
From source file:net.rim.ejde.internal.ui.editors.locale.ResourceEditorOptionsDialog.java
License:Open Source License
/** * Helper method updates the color of the table row (in resource editor) containing element. This is used by the * MarkTranslationCorrectAction and MarkTranslationIncorrectAction classes * * @param highlight/*from w w w . jav a 2s . com*/ * true if element should be marked as incorrect, false if it should be marked correct * @param element * the ResourceElement whose row color in the resource editor needs to be updated * * @see MarkTranslationCorrectAction * @see MarkTranslationIncorrectAction */ protected static void updateVersioningForResourceElementOnly(boolean highlight, ResourceElement element) { if (element instanceof RIMResourceElement) { Vector<ResourceEditorPage> pages = ResourceEditor.getResourceEditorPages(); for (int i = 0; i < pages.size(); i++) { if (pages.get(i).getRrcFile().getAbsolutePath() .equals(((RIMResourceElement) element).getLocale().getRrcFileAbsolutePath())) { TableViewer viewer = pages.get(i).getTableViewer(); Table table = viewer.getTable(); Color versioningColor = getVersioningColor(table); for (int j = 0; j < table.getItemCount(); j++) { if (table.getItem(j).getText(ResourceEditorPage.KEY_COLUMN_INDEX) .equals(((RIMResourceElement) element).getKey())) { if (highlight) { table.getItem(j).setBackground(versioningColor); } else { table.getItem(j).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } } } } } } }
From source file:net.rim.ejde.internal.ui.editors.locale.ResourceEditorOptionsDialog.java
License:Open Source License
/** * Helper method used to update versioning highlighting for a TableViewer object. This is used to preserve versioning * highlighting after user clicks on sort indicator in resource editor to sort resource key columns/values. * * @param turnOn/*from ww w .j a v a 2s . c o m*/ * true if versioning highlighting is to be turned on, false if it is to be turned off * @param viewer * the TableViewer object associated with a resource locale in the resource editor * @param locale * the ResourceLocale associated with viewer * * @see ResourceEditorPage */ protected static void updateVersioningForTableViewer(boolean turnOn, TableViewer viewer, ResourceLocale locale) { String originalLocaleString = ((RIMResourceLocale) locale).getCollection().getOriginalLocaleName(); Table table = viewer.getTable(); Color versioningColor = getVersioningColor(table); Hashtable originalLocaleHashTable = getOriginalLocaleHashtable(); // Reset colors in Resource Editor table widget to white prior to // highlighting for (int k = 0; k < table.getItemCount(); k++) { table.getItem(k).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } if (turnOn) { for (int j = 0; j < table.getItemCount(); j++) { String resourceKey = table.getItem(j).getText(ResourceEditorPage.KEY_COLUMN_INDEX); String originalLocaleChecksumHex = originalLocaleHashTable.get(resourceKey).toString().trim(); ResourceLocale resourceLocale = locale; long hash = ((RIMResourceLocale) resourceLocale).getResourceElement(resourceKey).getHash(); String currentLocaleChecksumHex = HEX_PREFIX + Long.toHexString(hash).toUpperCase(); if (originalLocaleChecksumHex.equals(currentLocaleChecksumHex)) { // Mark as correct table.getItem(j).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } else { // Check if current locale is the original locale boolean highlight = false; // boolean flag used to determine // whether we highlight the given // resource element String currentLocaleName = ((RIMResourceLocale) locale).getLocaleName(); if (currentLocaleName.equals(ResourceConstants.ROOT_LOCALE) && originalLocaleString.equals(ROOT)) { highlight = false; // do not highlight original locale // under any circumstances } else if (currentLocaleName.equals(originalLocaleString)) { highlight = false; // do not highlight original locale // under any circumstances } else { highlight = true; // mark as incorrect } if (highlight) { table.getItem(j).setBackground(versioningColor); } else { table.getItem(j).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } } } } }
From source file:net.rim.ejde.internal.ui.editors.locale.ResourceEditorOptionsDialog.java
License:Open Source License
/** * Helper method used to update versioning highlighting for all locales in resource bundle that locale belongs to. * * @param turnOn/* www .j a v a 2s . c o m*/ * true if versioning highlighting is to be turned on, false otherwise * @param locale * ResourceLocale object whose resource bundle needs to be updated on versioning highlighting */ protected static void updateVersioningForResourceEditor(boolean turnOn, ResourceLocale locale) { if (locale instanceof RIMResourceLocale) { // Update hash table first to ensure up to date mappings for // resource keys and resource value // checksums for the original locale generateOriginalLocaleHashtable(locale); File rrhFile = new File(((RIMResourceLocale) locale).getCollection().getRrhFileAbsolutePath()); String originalLocaleString = ((RIMResourceLocale) locale).getCollection().getOriginalLocaleName(); Vector<ResourceEditorPage> pages = ResourceEditor.getResourceEditorPages(); for (int i = 0; i < pages.size(); i++) { // Check if current ResourceEditorPage object in pages vector // belongs to this resource bundle String rrcPath = pages.get(i).getRrcFile().getAbsolutePath(); // . // rrc // file // in // pages // vector String rrhPath = rrhFile.getAbsolutePath(); // .rrh file from // which this // options dialog // was activated // from int indexOfRrhExt = rrhPath.lastIndexOf(ResourceConstants.RRH_SUFFIX); rrhPath = rrhPath.substring(0, indexOfRrhExt); rrcPath = rrcPath.substring(0, indexOfRrhExt); if (!rrhPath.equals(rrcPath)) { continue; // current ResourceEditorPage object is not in // this resource bundle, so skip to next object // prevents versioning highlighting from inadvertently being // turned on for other resource bundles (i.e. other // ResourceEditor instances) } TableViewer viewer = pages.get(i).getTableViewer(); Table table = viewer.getTable(); Color versioningColor = getVersioningColor(table); Hashtable originalLocaleHashTable = getOriginalLocaleHashtable(); // Reset colors in Resource Editor table widget to white prior // to highlighting for (int k = 0; k < table.getItemCount(); k++) { table.getItem(k).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } if (turnOn) { for (int j = 0; j < table.getItemCount(); j++) { String resourceKey = table.getItem(j).getText(ResourceEditorPage.KEY_COLUMN_INDEX); String originalLocaleChecksumHex = originalLocaleHashTable.get(resourceKey).toString() .trim(); ResourceLocale resourceLocale = pages.get(i).getLocale(); long hash = ((RIMResourceLocale) resourceLocale).getResourceElement(resourceKey).getHash(); String currentLocaleChecksumHex = HEX_PREFIX + Long.toHexString(hash).toUpperCase(); if (originalLocaleChecksumHex.equals(currentLocaleChecksumHex)) { // Marked correct table.getItem(j).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } else { // Check if current locale is the original locale boolean highlight = false; // boolean flag used to // determine whether we // highlight the given // resource element String currentLocaleName = ((RIMResourceLocale) pages.get(i).getLocale()) .getLocaleName(); if (currentLocaleName.equals(ResourceConstants.ROOT_LOCALE) && originalLocaleString.equals(ROOT)) { highlight = false; // do not highlight original // locale under any // circumstances } else if (currentLocaleName.equals(originalLocaleString)) { highlight = false; // do not highlight original // locale under any // circumstances } else { highlight = true; } // Highlight the appropriate table row in resource // editor page if necessary if (highlight) { table.getItem(j).setBackground(versioningColor); } else { table.getItem(j).setBackground(table.getDisplay().getSystemColor(SWT.COLOR_WHITE)); } } } } } } }
From source file:net.rim.ejde.internal.ui.editors.model.BlackBerryProjectPropertiesPage.java
License:Open Source License
/** * Adds the given object item to the given table if and only if the object does not already exist. Also updates button * controls.//from w ww. ja v a 2 s. c o m * * @param viewer * @param item * @param actionButtons */ public boolean addTableItem(TableViewer viewer, Object item, Map<Action, Button> actionButtons, boolean updateUIOnly) { if (updateUIOnly) { if (actionButtons.containsKey(Action.EDIT)) { actionButtons.get(Action.EDIT).setEnabled(true); } if (actionButtons.containsKey(Action.REMOVE)) { actionButtons.get(Action.REMOVE).setEnabled(true); } return true; } else { if (getObjectIndexInViewer(viewer, item) == -1) { if (item != null) { viewer.add(item); Table table = viewer.getTable(); table.select(table.getItemCount() - 1); // Used to fire any selection events viewer.setSelection(viewer.getSelection()); } if (actionButtons.containsKey(Action.EDIT)) { actionButtons.get(Action.EDIT).setEnabled(true); } if (actionButtons.containsKey(Action.REMOVE)) { actionButtons.get(Action.REMOVE).setEnabled(true); } return true; } return false; } }
From source file:net.rim.ejde.internal.ui.editors.model.BlackBerryProjectPropertiesPage.java
License:Open Source License
/** * Sets the given viewer to the given input. Convenience method that removes all existing data before setting the input. * * @param viewer// w w w . ja v a 2s .c o m * @param input */ public void setViewerInput(TableViewer viewer, Object[] input) { Arrays.sort(input); // Remove existing data viewer.setInput(null); viewer.getTable().removeAll(); viewer.setInput(input); viewer.refresh(true); }
From source file:net.rim.ejde.internal.ui.editors.model.BlackBerryProjectPropertiesPage.java
License:Open Source License
/** * Helper method that locates the given itemText and if found selects it. * * @param viewer/*from www.j a v a 2 s. co m*/ * @param itemText * @param actionButtons */ public void selectItemInViewer(TableViewer viewer, String itemText, Map<Action, Button> actionButtons) { Integer index = getItemIndex(viewer.getTable(), itemText); if (index != -1) { viewer.getTable().select(index); // Used to fire any selection events viewer.setSelection(viewer.getSelection()); if (actionButtons != null) { if (actionButtons.containsKey(Action.EDIT)) { actionButtons.get(Action.EDIT).setEnabled(true); } if (actionButtons.containsKey(Action.REMOVE)) { actionButtons.get(Action.REMOVE).setEnabled(true); } if (actionButtons.containsKey(Action.MOVE_UP)) { if (viewer.getTable().getItemCount() > 1) { actionButtons.get(Action.MOVE_UP).setEnabled(true); } } if (actionButtons.containsKey(Action.MOVE_DOWN)) { actionButtons.get(Action.MOVE_DOWN) .setEnabled(index < viewer.getTable().getItemCount() - 1 ? true : false); } } } }