List of usage examples for org.eclipse.jface.viewers ITableLabelProvider ITableLabelProvider
ITableLabelProvider
From source file:com.amalto.workbench.dialogs.AnnotationOrderedListsDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { // Should not really be here but well,.... parent.getShell().setText(this.title); Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = (GridLayout) composite.getLayout(); layout.numColumns = 3;// w w w. jav a 2s . c o m layout.makeColumnsEqualWidth = false; // layout.verticalSpacing = 10; if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType) { textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY); // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE); roles = getAllRolesStr(); ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()])); } else if (actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) { textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY); // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE); roles = getConceptElements(); ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()])); } else { if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) { textControl = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); } else { textControl = new Text(composite, SWT.BORDER | SWT.SINGLE); } } if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) { textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); } else { if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) { textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 7)); } else { textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); } } ((GridData) textControl.getLayoutData()).minimumWidth = 400; textControl.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if ((e.stateMask == 0) && (e.character == SWT.CR)) { xPaths.add(AnnotationOrderedListsDialog.getControlText(textControl)); viewer.refresh(); fireXPathsChanges(); } } }); if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) { Button xpathButton = new Button(composite, SWT.PUSH | SWT.CENTER); xpathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); xpathButton.setText("...");//$NON-NLS-1$ xpathButton.setToolTipText(Messages.AnnotationOrderedListsDialog_SelectXpath); xpathButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { XpathSelectDialog dlg = getNewXpathSelectDialog(parentPage, dataModelName); dlg.setLock(lock); dlg.setBlockOnOpen(true); dlg.open(); if (dlg.getReturnCode() == Window.OK) { ((Text) textControl).setText(dlg.getXpath()); dlg.close(); } } }); } Button addLabelButton = new Button(composite, SWT.PUSH); addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); // addLabelButton.setText("Set"); addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath())); addLabelButton.setToolTipText(Messages.AnnotationOrderedListsDialog_Add); addLabelButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { boolean exist = false; for (String string : xPaths) { if (string.equals(getControlText(textControl))) { exist = true; } } if (!exist && getControlText(textControl) != null && getControlText(textControl) != "") { xPaths.add(getControlText(textControl)); } viewer.refresh(); fireXPathsChanges(); }; }); final String COLUMN = columnName; viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); ((GridData) viewer.getControl().getLayoutData()).heightHint = 100; // Set up the underlying table Table table = viewer.getTable(); // table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.CENTER).setText(COLUMN); table.getColumn(0).setWidth(500); for (int i = 1, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); // Create the cell editors --> We actually discard those later: not natural for an user CellEditor[] editors = new CellEditor[1]; if (actionType == AnnotationOrderedListsDialog.AnnotationWrite_ActionType || actionType == AnnotationOrderedListsDialog.AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) { editors[0] = new ComboBoxCellEditor(table, roles.toArray(new String[] {}), SWT.READ_ONLY); } else { editors[0] = new TextCellEditor(table); } viewer.setCellEditors(editors); // set the content provider viewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object inputElement) { @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) inputElement; ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>(); for (String xPath : xPaths) { DescriptionLine line = new DescriptionLine(xPath); lines.add(line); } // we return an instance line made of a Sring and a boolean return lines.toArray(new DescriptionLine[lines.size()]); } }); // set the label provider viewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { // System.out.println("getColumnText() "+columnIndex); DescriptionLine line = (DescriptionLine) element; switch (columnIndex) { case 0: return line.getLabel(); } return "";//$NON-NLS-1$ } public Image getColumnImage(Object element, int columnIndex) { return null; } }); // Set the column properties viewer.setColumnProperties(new String[] { COLUMN }); // set the Cell Modifier viewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated return true; // return false; } public void modify(Object element, String property, Object value) { TableItem item = (TableItem) element; DescriptionLine line = (DescriptionLine) item.getData(); String orgValue = line.getLabel(); if (actionType != AnnotationWrite_ActionType && actionType != AnnotationHidden_ActionType && actionType != AnnotationLookupField_ActionType && actionType != AnnotationPrimaKeyInfo_ActionType) { int targetPos = xPaths.indexOf(value.toString()); if (targetPos < 0) { line.setLabel(value.toString()); int index = xPaths.indexOf(orgValue); xPaths.remove(index); xPaths.add(index, value.toString()); viewer.update(line, null); } else if (targetPos >= 0 && !value.toString().equals(orgValue)) { MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_ValueAlreadyExists); } } else { String[] attrs = roles.toArray(new String[] {}); int index = Integer.parseInt(value.toString()); if (index == -1) { return; } value = attrs[index]; int pos = xPaths.indexOf(value.toString()); if (pos >= 0 && !(orgValue.equals(value))) { MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_); return; } else if (pos < 0) { line.setLabel(value.toString()); xPaths.set(index, value.toString()); viewer.update(line, null); } } fireXPathsChanges(); } public Object getValue(Object element, String property) { DescriptionLine line = (DescriptionLine) element; String value = line.getLabel(); if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) { String[] attrs = roles.toArray(new String[] {}); return Arrays.asList(attrs).indexOf(value); } else { return value; } } }); // Listen for changes in the selection of the viewer to display additional parameters viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); if (line != null) { if (textControl instanceof CCombo) { ((CCombo) textControl).setText(line.getLabel()); } if (textControl instanceof Text) { ((Text) textControl).setText(line.getLabel()); } } } }); // display for Delete Key events to delete an instance viewer.getTable().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { // System.out.println("Table keyReleased() "); if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput(); xPaths.remove(line.getLabel()); viewer.refresh(); } } }); viewer.setInput(xPaths); viewer.refresh(); Composite rightButtonsComposite = new Composite(composite, SWT.NULL); rightButtonsComposite.setLayout(new GridLayout(1, true)); rightButtonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); Button upButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER); upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath())); upButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveUpTheItem); upButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); if (line == null) { return; } int i = 0; for (String xPath : xPaths) { if (xPath.equals(line.getLabel())) { if (i > 0) { xPaths.remove(i); xPaths.add(i - 1, xPath); viewer.refresh(); viewer.getTable().setSelection(i - 1); viewer.getTable().showSelection(); fireXPathsChanges(); } return; } i++; } }; }); Button downButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER); downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath())); downButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveDownTheItem); downButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); if (line == null) { return; } int i = 0; for (String xPath : xPaths) { if (xPath.equals(line.getLabel())) { if (i < xPaths.size() - 1) { xPaths.remove(i); xPaths.add(i + 1, xPath); viewer.refresh(); viewer.getTable().setSelection(i + 1); viewer.getTable().showSelection(); fireXPathsChanges(); } return; } i++; } }; }); Button delButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER); delButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); delButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath())); delButton.setToolTipText(Messages.AnnotationOrderedListsDialog_DelTheItem); delButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); if (line != null) { @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput(); xPaths.remove(line.getLabel()); viewer.refresh(); fireXPathsChanges(); } }; }); textControl.setFocus(); if (actionType != AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationSchematron_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationLookupField_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType) { checkBox = new Button(composite, SWT.CHECK); checkBox.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 2, 1)); checkBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { recursive = checkBox.getSelection(); }; }); checkBox.setSelection(recursive); checkBox.setText(Messages.AnnotationOrderedListsDialog_SetRoleRecursively); // Label label = new Label(composite, SWT.LEFT); // label.setText("set role recursively"); // label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, // 1, 1)); } if (actionType == AnnotationForeignKeyInfo_ActionType) { createFKInfoFormatComp(composite); addDoubleClickListener(); } return composite; }
From source file:com.amalto.workbench.dialogs.MenuEntryDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { // Should not really be here but well,.... parent.getShell().setText(this.title); Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = (GridLayout) composite.getLayout(); layout.numColumns = 3;//from w w w. j a va2 s . com // layout.verticalSpacing = 10; Label idLabel = new Label(composite, SWT.NONE); idLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); idLabel.setText(Messages.MenuEntryDialog_Id); if (this.isChanged) { idText = new Text(composite, SWT.NONE); } else { idText = new Text(composite, SWT.NONE | SWT.READ_ONLY); } idText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); ((GridData) idText.getLayoutData()).widthHint = 300; idText.setDoubleClickEnabled(false); Label contextLabel = new Label(composite, SWT.NONE); contextLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); contextLabel.setText(Messages.MenuEntryDialog_Context); contextText = new Text(composite, SWT.NONE); contextText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); contextText.setDoubleClickEnabled(false); Label applicationNameLabel = new Label(composite, SWT.NONE); applicationNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); applicationNameLabel.setText(Messages.MenuEntryDialog_Application); applicationNameText = new Text(composite, SWT.NONE); applicationNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Label iconPathLabel = new Label(composite, SWT.NONE); iconPathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); iconPathLabel.setText(Messages.MenuEntryDialog_IconPath); iconPathText = new FileSelectWidget(composite, "", new String[] { "*.png", "*.gif", "*.jpg" }, "", true);//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$ // Labels descriptionsComposite = new Composite(composite, SWT.BORDER); descriptionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); descriptionsComposite.setLayout(new GridLayout(3, false)); Label descriptionsLabel = new Label(descriptionsComposite, SWT.NULL); descriptionsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); descriptionsLabel.setText(Messages.MenuEntryDialog_MenuEntryLabels); languagesCombo = new Combo(descriptionsComposite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE); languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1)); Set<String> languages = Util.lang2iso.keySet(); for (Object element : languages) { String language = (String) element; languagesCombo.add(language); } languagesCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { } }); languagesCombo.select(0); labelText = new Text(descriptionsComposite, SWT.BORDER | SWT.SINGLE); labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); labelText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if ((e.stateMask == 0) && (e.character == SWT.CR)) { String isoCode = Util.lang2iso.get(languagesCombo.getText()); descriptionsMap.put(isoCode, labelText.getText()); descriptionsViewer.refresh(); } } }); Button addLabelButton = new Button(descriptionsComposite, SWT.PUSH); addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath())); addLabelButton.setToolTipText(Messages.MenuEntryDialog_Add); addLabelButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String isoCode = Util.lang2iso.get(languagesCombo.getText()); descriptionsMap.put(isoCode, labelText.getText()); descriptionsViewer.refresh(); }; }); final String LANGUAGE = Messages.MenuEntryDialog_Language; final String LABEL = Messages.MenuEntryDialog_Label; descriptionsViewer = new TableViewer(descriptionsComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100; // Set up the underlying table Table table = descriptionsViewer.getTable(); // table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.LEFT).setText(LANGUAGE); new TableColumn(table, SWT.CENTER).setText(LABEL); table.getColumn(0).setWidth(150); table.getColumn(1).setWidth(150); for (int i = 2, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); // Create the cell editors --> We actually discard those later: not natural for an user CellEditor[] editors = new CellEditor[2]; editors[0] = new TextCellEditor(table); editors[1] = new TextCellEditor(table); descriptionsViewer.setCellEditors(editors); // set the content provider descriptionsViewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object inputElement) { // System.out.println("getElements() "); LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement; Set<String> languages = descs.keySet(); ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>(); for (Object element : languages) { String language = (String) element; DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language)); lines.add(line); } // we return an instance line made of a Sring and a boolean return lines.toArray(new DescriptionLine[lines.size()]); } }); // set the label provider descriptionsViewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { // System.out.println("getColumnText() "+columnIndex); DescriptionLine line = (DescriptionLine) element; switch (columnIndex) { case 0: return line.getLanguage(); case 1: return line.getLabel(); } return "";//$NON-NLS-1$ } public Image getColumnImage(Object element, int columnIndex) { return null; } }); // Set the column properties descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL }); // set the Cell Modifier descriptionsViewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated return false; } public void modify(Object element, String property, Object value) { // System.out.println("modify() "+element.getClass().getName()+": "+property+": "+value); // DescriptionLine line = // (DescriptionLine)((IStructuredSelection)instancesViewer.getSelection()).getFirstElement(); // deactivated: editing in places is not natural for users } public Object getValue(Object element, String property) { // System.out.println("getValue() "+property); DescriptionLine line = (DescriptionLine) element; if (LANGUAGE.equals(property)) { return line.getLanguage(); } if (LABEL.equals(property)) { return line.getLabel(); } return null; } }); // Listen for changes in the selection of the viewer to display additional parameters descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { } }); // display for Delete Key events to delete an instance descriptionsViewer.getTable().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { // System.out.println("Table keyReleased() "); if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) { DescriptionLine line = (DescriptionLine) ((IStructuredSelection) descriptionsViewer .getSelection()).getFirstElement(); String isoCode = Util.lang2iso.get(line.getLanguage()); LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) descriptionsViewer .getInput(); descs.remove(isoCode); descriptionsViewer.refresh(); } } }); descriptionsViewer.refresh(); if (wsMenuEntry != null) { idText.setText(wsMenuEntry.getId() == null ? "" : wsMenuEntry.getId());//$NON-NLS-1$ contextText.setText(wsMenuEntry.getContext() == null ? "" : wsMenuEntry.getContext());//$NON-NLS-1$ applicationNameText.setText(wsMenuEntry.getApplication() == null ? "" : wsMenuEntry.getApplication());//$NON-NLS-1$ iconPathText.setFilename(wsMenuEntry.getIcon() == null ? "" : wsMenuEntry.getIcon());//$NON-NLS-1$ descriptionsViewer.setInput(descriptionsMap); } idText.setFocus(); return composite; }
From source file:com.amalto.workbench.dialogs.VariableDefinitionDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { parent.getShell().setText(title);// w ww . ja v a 2 s. c o m Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = (GridLayout) composite.getLayout(); layout.numColumns = 2; descriptionsViewer = new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100; // Set up the underlying table Table table = descriptionsViewer.getTable(); final String columnTitle = Messages.VariableDefinitionDialog_AvailableVariables; new TableColumn(table, SWT.CENTER).setText(columnTitle); table.getColumn(0).setWidth(350); table.setHeaderVisible(true); table.setLinesVisible(true); CellEditor[] editors = new CellEditor[1]; editors[0] = new TextCellEditor(table); descriptionsViewer.setCellEditors(editors); descriptionsViewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } public Object[] getElements(Object inputElement) { ArrayList<String> descs = (ArrayList<String>) inputElement; return descs.toArray(); } }); // set the label provider descriptionsViewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { // return element.toString().toLowerCase(); return element.toString(); } public Image getColumnImage(Object element, int columnIndex) { return null; } }); descriptionsViewer.setColumnProperties(new String[] { columnTitle }); descriptionsViewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { return false; } public void modify(Object element, String property, Object value) { } public Object getValue(Object element, String property) { return element.toString(); } }); descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); outPut = (String) selection.getFirstElement(); getButton(IDialogConstants.OK_ID).setEnabled(true); } }); descriptionsViewer.setInput(inputList); descriptionsViewer.refresh(); return composite; }
From source file:com.amalto.workbench.widgets.ComplexTableViewer.java
License:Open Source License
protected void createViewer() { createTable();//from ww w . j a v a 2 s . com GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, columns.size(), 1); table.setLayoutData(gd); gd.heightHint = 80; // Up Down Delete button group Composite stepUpDownComposite = toolkit.createComposite(mainComposite, SWT.NONE); stepUpDownComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1)); stepUpDownComposite.setLayout(new GridLayout(1, false)); upButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath())); upButton.setToolTipText(Messages.ComplexTableViewer_UpBtnTip); upButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { int index = viewer.getTable().getSelectionIndex(); if (index > 0 && index < viewer.getTable().getItemCount()) { // commit as we go if (mainPage != null) { mainPage.setComitting(true); } List<Line> items = (List<Line>) viewer.getInput(); Line line = items.get(index); items.remove(index); items.add(index - 1, line); viewer.refresh(); if (mainPage != null) { mainPage.setComitting(false); } markDirty(); } }; }); downButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath())); downButton.setToolTipText(Messages.ComplexTableViewer_DownBtnTip); downButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { int index = viewer.getTable().getSelectionIndex(); if (index >= 0 && index < viewer.getTable().getItemCount() - 1) { // commit as we go if (mainPage != null) { mainPage.setComitting(true); } List<Line> items = (List<Line>) viewer.getInput(); Line line = items.get(index); items.remove(index); items.add(index + 1, line); // viewer.setInput(items); viewer.refresh(); // TODO if (mainPage != null) { mainPage.setComitting(false); } markDirty(); } }; }); deleteButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); deleteButton.setToolTipText(Messages.ComplexTableViewer_DelBtnLabel); deleteButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath())); deleteButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { int index = viewer.getTable().getSelectionIndex(); if (index >= 0 && index < viewer.getTable().getItemCount()) { List<Line> items = (List<Line>) viewer.getInput(); items.remove(index); viewer.refresh(); int pos = index - 1; if (pos >= 0) { viewer.getTable().select(pos); } markDirty(); } }; }); // Create the cell editors --> We actually discard those later: not natural for an user CellEditor[] editors = new CellEditor[columns.size()]; for (int i = 0; i < columns.size(); i++) { if (columns.get(i).isText()) { editors[i] = new TextCellEditor(table); } else if (columns.get(i).isCombo()) { editors[i] = new ComboBoxCellEditor(table, columns.get(i).getComboValues(), SWT.READ_ONLY); } else if (columns.get(i).isXPATH()) { editors[i] = new XpathCellEditor(table, validators.get(columns.get(i))); } else if (columns.get(i).isMultiMessage()) { editors[i] = new MultiMessageEditor(table); multiMsg.setColumn(table.getColumn(i)); } else if (columns.get(i).isValidationRule()) { editors[i] = new ValidationRuleEditor(table); validationRule.setColumn(table.getColumn(i)); } } viewer.setCellEditors(editors); // set the content provider viewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @SuppressWarnings("unchecked") public Object[] getElements(Object inputElement) { List<Line> lines = (List<Line>) inputElement; return lines.toArray(new Line[lines.size()]); } }); // set the label provider viewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { Line line = (Line) element; if (columnIndex >= 0 && columnIndex < columns.size()) { for (KeyValue keyvalue : line.keyValues) { if (keyvalue.key.equals(columns.get(columnIndex).getName())) { String val = keyvalue.value; if (columns.get(columnIndex).isNillable()) { if (columns.get(columnIndex).getNillValue().equals(val)) { val = columns.get(columnIndex).getNillDisplay(); } } return val; } } } return "";//$NON-NLS-1$ } public Image getColumnImage(Object element, int columnIndex) { return null; } }); // Set the column properties ArrayList<String> columnNames = new ArrayList<String>(); for (ComplexTableViewerColumn column : columns) { columnNames.add(column.getName()); } viewer.setColumnProperties(columnNames.toArray(new String[columnNames.size()])); // set the Cell Modifier viewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated return editable; } @SuppressWarnings("unchecked") public void modify(Object element, String property, Object value) { if (value instanceof Integer) { if (Integer.valueOf(value.toString()) == -1) { return; } } // modify the text and combo cell value TableItem item = (TableItem) element; Line line = (Line) item.getData(); int columnIndex = Arrays.asList(viewer.getColumnProperties()).indexOf(property); if (!isForceTextCellEditor(columnIndex) && isAColumnWithCombo(columnIndex)) { String[] attrs = columns.get(columnIndex).getComboValues(); value = attrs[Integer.parseInt(value.toString())]; } KeyValue kv = line.keyValues.get(columnIndex); boolean noChange = kv.value.equals(value.toString()); kv.value = value.toString(); viewer.refresh(); if (!noChange) { markDirty(); } } public Object getValue(Object element, String property) { int columnIndex = Arrays.asList(viewer.getColumnProperties()).indexOf(property); Line line = (Line) element; // add getting value from combo if (isAColumnWithCombo(columnIndex)) { String value = line.keyValues.get(columnIndex).value; String[] attrs = columns.get(columnIndex).getComboValues(); return Arrays.asList(attrs).indexOf(value); } for (KeyValue keyvalue : line.keyValues) { if (property.equals(keyvalue.key)) { if (keyvalue.value.equals("")) {//$NON-NLS-1$ return columns.get(columnIndex).getNillDisplay(); } return keyvalue.value; } } return null; } private boolean isAColumnWithCombo(int columnIdx) { return columns.get(columnIdx).isCombo(); } private boolean isForceTextCellEditor(int columnIdx) { return columns.get(columnIdx).isText(); } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { Line line = (Line) ((IStructuredSelection) event.getSelection()).getFirstElement(); for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) { if (line == null) { Control control = columns.get(columnIndex).getControl(); if (control instanceof Text) { ((Text) control).setText("");//$NON-NLS-1$ } if (control instanceof CCombo) { ((CCombo) control).select(0); } if (control instanceof Combo) { ((CCombo) control).select(0); } } else { for (KeyValue keyvalue : line.keyValues) { if (keyvalue.key.equals(columns.get(columnIndex).getName())) { String val = keyvalue.value; Control control = columns.get(columnIndex).getControl(); if (control instanceof Text) { ((Text) control).setText(val); } if (control instanceof CCombo) { ((CCombo) control).setText(val); } if (control instanceof Combo) { ((CCombo) control).setText(val); } } } } } } }); // display for Delete Key events to delete an instance viewer.getTable().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } @SuppressWarnings("unchecked") public void keyReleased(KeyEvent e) { if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) { Line line = (Line) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); // update the underlying role and refresh the table // update the underlying model List<Line> items = (List<Line>) viewer.getInput(); items.remove(line); // refresh viewer.refresh(); // mark for update markDirty(); } } }); }
From source file:com.amalto.workbench.widgets.TisTableViewer.java
License:Open Source License
@Override protected void createViewer() { super.createTable(); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); table.setLayoutData(gd);//from w ww .j a va 2s. co m gd.heightHint = 80; // Up Down Delete button group Composite stepUpDownComposite = toolkit.createComposite(mainComposite, SWT.NONE); stepUpDownComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); GridLayout layout = new GridLayout(8, false); layout.marginTop = 0; layout.marginBottom = 0; layout.marginHeight = 0; stepUpDownComposite.setLayout(layout); // addButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); addButton.setToolTipText(Messages.Add); if (isXpath()) { addButton.setImage(ImageCache.getCreatedImage(EImage.ADD_NEWXPATH.getPath())); } else { addButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath())); } addButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { // check uniqueness by concatenating all the values List<Line> list = (List<Line>) getViewer().getInput(); // Update the model Line line = new Line(columns.toArray(new ComplexTableViewerColumn[columns.size()]), getInitValues()); list.add(line); viewer.setInput(list); // update the instances viewer viewer.setSelection(null); viewer.refresh(); viewer.getTable().select(viewer.getTable().getItemCount() - 1); markDirty(); }; }); // Add Multi if (isAddMulti()) { Button selNewPathButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ selNewPathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); selNewPathButton.setToolTipText(Messages.AddMultiple); selNewPathButton.setImage(ImageCache.getCreatedImage(EImage.SELECT_NEWXPATH.getPath())); selNewPathButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { xpathDialog = getNewXpathDlgInstance(); xpathDialog.setConceptName(conceptName); xpathDialog.setBlockOnOpen(true); xpathDialog.open(); if (xpathDialog.getReturnCode() == Window.OK) { datamodelName = xpathDialog.getDataModelName(); String[] xpaths = xpathDialog.getXpath().split("&");//$NON-NLS-1$ List<Line> list = new LinkedList<Line>(); for (String xpath : xpaths) { // check uniqueness by concatenating all the values list = (List<Line>) getViewer().getInput(); // Update the model Line line = new Line(columns.toArray(new ComplexTableViewerColumn[columns.size()]), getLineValues(xpath, 0)); list.add(line); } viewer.setInput(list); // update the instances viewer viewer.setSelection(null); viewer.refresh(); viewer.getTable().select(viewer.getTable().getItemCount() - 1); markDirty(); } }; }); } deleteButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ deleteButton.setToolTipText(Messages.DeleteSelectedItem); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); deleteButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { List<Line> input = (List<Line>) viewer.getInput(); TableItem[] items = viewer.getTable().getSelection(); for (int i = 0; i < items.length; i++) { input.remove(items[i].getData()); } viewer.setInput(input); markDirty(); }; }); deleteButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath())); // delete all Button deleteAllButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ deleteAllButton.setToolTipText(Messages.DeleteAllItems); deleteAllButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); deleteAllButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { List<Line> items = (List<Line>) viewer.getInput(); items.clear(); viewer.setInput(items); viewer.refresh(); markDirty(); }; }); deleteAllButton.setImage(ImageCache.getCreatedImage(EImage.PROGRESS_REMALL.getPath())); upButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ upButton.setToolTipText(Messages.MoveUpSelectedItem); upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath())); upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); upButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { int index = viewer.getTable().getSelectionIndex(); if (index > 0 && index < viewer.getTable().getItemCount()) { // commit as we go if (mainPage != null) { mainPage.setComitting(true); } List<Line> items = (List<Line>) viewer.getInput(); Line line = items.get(index); items.remove(index); items.add(index - 1, line); viewer.refresh(); if (mainPage != null) { mainPage.setComitting(false); } markDirty(); } }; }); downButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ downButton.setToolTipText(Messages.MovedownSelectedItem); downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath())); downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); downButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { int index = viewer.getTable().getSelectionIndex(); if (index >= 0 && index < viewer.getTable().getItemCount() - 1) { // commit as we go if (mainPage != null) { mainPage.setComitting(true); } List<Line> items = (List<Line>) viewer.getInput(); Line line = items.get(index); items.remove(index); items.add(index + 1, line); // viewer.setInput(items); viewer.refresh(); // TODO if (mainPage != null) { mainPage.setComitting(false); } markDirty(); } }; }); copyButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ copyButton.setToolTipText(Messages.CopySelectedItems); copyButton.setImage(ImageCache.getCreatedImage(EImage.COPY.getPath())); copyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); copyButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { int[] indexs = viewer.getTable().getSelectionIndices(); List<Line> copyLines = new ArrayList<Line>(); for (int index : indexs) { if (index >= 0 && index <= viewer.getTable().getItemCount() - 1) { List<Line> items = (List<Line>) viewer.getInput(); Line line = items.get(index); Line copyLine = line.clone(); copyLines.add(copyLine); } } if (indexs.length > 0) { // enable all paste buttons HashSet<Button> btns = pastBtns.get(String.valueOf(columns.size())); if (btns != null) { for (Button btn : btns) { if (btn != null) { btn.setEnabled(true); } } } // add to workbenchclipboard WorkbenchClipboard.getWorkbenchClipboard().setLines(String.valueOf(columns.size()), copyLines); } } }); pastButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$ pastButton.setToolTipText(Messages.PasteSelectedItem); pastButton.setImage(ImageCache.getCreatedImage(EImage.PASTE.getPath())); pastButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); pastButton.setEnabled(false); pastButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) { }; @SuppressWarnings("unchecked") public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { if (mainPage != null) { mainPage.setComitting(true); } boolean dirty = false; List<Line> items = (List<Line>) viewer.getInput(); List<Line> cacheLine = WorkbenchClipboard.getWorkbenchClipboard() .getLines(String.valueOf(columns.size())); List<Line> coloneLine = new ArrayList<Line>(); for (Line l : cacheLine) { coloneLine.add(l.clone()); } if (cacheLine.size() > 0) { items.addAll(coloneLine); dirty = true; } viewer.refresh(); // TODO if (mainPage != null) { mainPage.setComitting(false); } if (dirty) { markDirty(); } }; }); HashSet<Button> btns = pastBtns.get(String.valueOf(columns.size())); if (btns == null) { btns = new HashSet<Button>(); pastBtns.put(String.valueOf(columns.size()), btns); } btns.add(pastButton); // Create the cell editors --> We actually discard those later: not natural for an user CellEditor[] editors = new CellEditor[columns.size()]; for (int i = 0; i < columns.size(); i++) { if (columns.get(i).isText()) { editors[i] = new TextCellEditor(table); } else if (columns.get(i).isCombo()) { editors[i] = new ComboBoxCellEditor(table, columns.get(i).getComboValues(), SWT.READ_ONLY); } else if (columns.get(i).isXPATH()) { editors[i] = new XpathCellEditor(table, validators.get(columns.get(i))); } else if (columns.get(i).isMultiMessage()) { editors[i] = new MultiMessageEditor(table); multiMsg.setColumn(table.getColumn(i)); } else if (columns.get(i).isValidationRule()) { editors[i] = createValidationRuleEditor(); validationRule.setColumn(table.getColumn(i)); } } viewer.setCellEditors(editors); // set the content provider viewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @SuppressWarnings("unchecked") public Object[] getElements(Object inputElement) { ArrayList<Line> lines = (ArrayList<Line>) inputElement; return lines.toArray(new Line[lines.size()]); } }); // set the label provider viewer.setLabelProvider(new ITableLabelProvider() { public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public void removeListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { Line line = (Line) element; if (columnIndex >= 0 && columnIndex < columns.size()) { for (KeyValue keyvalue : line.keyValues) { if (keyvalue.key.equals(columns.get(columnIndex).getName())) { String val = keyvalue.value; if (columns.get(columnIndex).isNillable()) { if (columns.get(columnIndex).getNillValue().equals(val)) { val = columns.get(columnIndex).getNillDisplay(); } } return val; } } } return "";//$NON-NLS-1$ } public Image getColumnImage(Object element, int columnIndex) { return null; } }); // Set the column properties ArrayList<String> columnNames = new ArrayList<String>(); for (ComplexTableViewerColumn column : columns) { columnNames.add(column.getName()); } viewer.setColumnProperties(columnNames.toArray(new String[columnNames.size()])); // set the Cell Modifier viewer.setCellModifier(new ICellModifier() { public boolean canModify(Object element, String property) { return editable; } @SuppressWarnings("unchecked") public void modify(Object element, String property, Object value) { if (value instanceof Integer) { if (Integer.valueOf(value.toString()) == -1) { return; } } // modify the text and combo cell value TableItem item = (TableItem) element; Line line = (Line) item.getData(); int columnIndex = Arrays.asList(viewer.getColumnProperties()).indexOf(property); if (columnIndex >= 0 && columnIndex < viewer.getColumnProperties().length) { if (isAColumnWithCombo(columnIndex)) { String[] attrs = columns.get(columnIndex).getComboValues(); value = attrs[Integer.parseInt(value.toString())]; } KeyValue kv = line.keyValues.get(columnIndex); boolean noChange = kv.value.equals(value.toString()); kv.value = value.toString(); viewer.refresh(); if (!noChange) { markDirty(); } } } public Object getValue(Object element, String property) { int columnIndex = Arrays.asList(viewer.getColumnProperties()).indexOf(property); Line line = (Line) element; // add getting value from combo if (isAColumnWithCombo(columnIndex)) { String value = line.keyValues.get(columnIndex).value; String[] attrs = columns.get(columnIndex).getComboValues(); return Arrays.asList(attrs).indexOf(value); } for (KeyValue keyvalue : line.keyValues) { if (property.equals(keyvalue.key)) { if (keyvalue.value.equals("")) {//$NON-NLS-1$ return columns.get(columnIndex).getNillDisplay(); } return keyvalue.value; } } return null; } private boolean isAColumnWithCombo(int columnIdx) { return columns.get(columnIdx).isCombo(); } }); // display for Delete Key events to delete an instance viewer.getTable().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { } @SuppressWarnings("unchecked") public void keyReleased(KeyEvent e) { if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) { Line line = (Line) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); // update the underlying role and refresh the table // update the underlying model List<Line> items = (List<Line>) viewer.getInput(); items.remove(line); // refresh viewer.refresh(); // mark for update markDirty(); } } }); // add dispose listener viewer.getTable().addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { HashSet<Button> btns = pastBtns.get(String.valueOf(columns.size())); btns.remove(pastButton); } }); }
From source file:com.amalto.workbench.widgets.VersionTagWidget.java
License:Open Source License
public VersionTagWidget(Composite parent, String resourcesName, String defaultTagText, boolean isTagEditable, SelectionListener tagSelectionListener, SelectionListener restoreSelectionListener, // *** TMDM-8080, temp substituted start ***// // IDoubleClickListener tagsViewerDoubleClickListener, List<TagStructure> hisEntries) { IDoubleClickListener tagsViewerDoubleClickListener, List<Object> hisEntries) { // *** TMDM-8080, temp substituted end ***// composite = new Composite(parent, SWT.FILL); GridLayout layout = new GridLayout(); layout.numColumns = 1;//from w w w.j a va 2s.c om composite.setLayout(layout); Group tagGroup = new Group(composite, SWT.SHADOW_NONE); tagGroup.setLayout(new GridLayout(2, false)); tagGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tagGroup.setText(Messages.bind(Messages.VersionTagWidget_GroupTextX, resourcesName)); Label tagLabel = new Label(tagGroup, SWT.NONE); tagLabel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); tagLabel.setText(Messages.VersionTagWidget_GroupText); tagText = new Text(tagGroup, SWT.BORDER); tagText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); if (defaultTagText == null) { defaultTagText = "";//$NON-NLS-1$ } tagText.setText(defaultTagText); tagText.setEditable(isTagEditable); Label commentLabel = new Label(tagGroup, SWT.NONE); commentLabel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1)); commentLabel.setText(Messages.VersionTagWidget_Comment); commentText = new Text(tagGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); commentText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); commentText.setText("");//$NON-NLS-1$ ((GridData) commentText.getLayoutData()).widthHint = 250; ((GridData) commentText.getLayoutData()).heightHint = 25; commentText.forceFocus(); tagButton = new Button(tagGroup, SWT.PUSH); tagButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); tagButton.setText(Messages.VersionTagWidget_GroupText); tagButton.addSelectionListener(tagSelectionListener); restoreGroup = new Group(composite, SWT.SHADOW_NONE); restoreGroup.setLayout(new GridLayout(1, true)); restoreGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); restoreGroup.setText(Messages.bind(Messages.VersionTagWidget_RestoreX, resourcesName)); restoreGroup.setEnabled(false); tagsViewer = new TableViewer(restoreGroup); tagsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); ((GridData) tagsViewer.getControl().getLayoutData()).heightHint = 150; ((GridData) tagsViewer.getControl().getLayoutData()).widthHint = 250; tagsViewer.setContentProvider(new ArrayContentProvider()); tagsViewer.setLabelProvider(new ITableLabelProvider() { public String getColumnText(Object element, int columnIndex) { // *** TMDM-8080, temp substituted start ***// // TagStructure entry = (TagStructure) element; // return entry.getTagName() + " - " + entry.getLastComment() + " [" + entry.getLastDate() + " "//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ // + entry.getLastAuthor() + "]";//$NON-NLS-1$ return element.toString(); // *** TMDM-8080, temp substituted end ***// } public Image getColumnImage(Object element, int columnIndex) { return null; } public void addListener(ILabelProviderListener listener) { } public void dispose() { } public boolean isLabelProperty(Object element, String property) { return false; } public void removeListener(ILabelProviderListener listener) { } }); tagsViewer.addDoubleClickListener(tagsViewerDoubleClickListener); restoreButton = new Button(restoreGroup, SWT.PUSH); restoreButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); restoreButton.setText(Messages.VersionTagWidget_Restore); restoreButton.addSelectionListener(restoreSelectionListener); // *** TMDM-8080, temp omitted start ***// // refreshData(hisEntries); // *** TMDM-8080, temp omitted end ***// }
From source file:com.amazonaws.eclipse.elasticbeanstalk.server.ui.configEditor.EventLogEditorSection.java
License:Open Source License
private void createEventsTable(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); TreeColumnLayout treeColumnLayout = new TreeColumnLayout(); composite.setLayout(treeColumnLayout); int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI; viewer = new TreeViewer(composite, style); viewer.getTree().setLinesVisible(true); viewer.getTree().setHeaderVisible(true); addContextMenu();// ww w . j a va2 s . c om newColumn("Message", 75); newColumn("Version", 10); newColumn("Date", 15); viewer.setContentProvider(new ITreeContentProvider() { private List<EventDescription> events; @SuppressWarnings("unchecked") public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput == null) events = new ArrayList<EventDescription>(); else events = (List<EventDescription>) newInput; } public void dispose() { } public Object[] getElements(Object inputElement) { return events.toArray(); } public Object[] getChildren(Object parentElement) { return new Object[0]; } public Object getParent(Object element) { return null; } public boolean hasChildren(Object element) { return false; } }); viewer.setLabelProvider(new ITableLabelProvider() { public void removeListener(ILabelProviderListener listener) { } public boolean isLabelProperty(Object element, String property) { return false; } public void dispose() { } public void addListener(ILabelProviderListener listener) { } public String getColumnText(Object element, int columnIndex) { EventDescription event = (EventDescription) element; switch (columnIndex) { case 0: return event.getMessage(); case 1: return event.getVersionLabel(); case 2: return event.getEventDate().toString(); default: return ""; } } public Image getColumnImage(Object element, int columnIndex) { if (element == null) return null; if (columnIndex != 0) return null; EventSeverity eventSeverity = null; try { EventDescription event = (EventDescription) element; eventSeverity = EventSeverity.fromValue(event.getSeverity()); } catch (IllegalArgumentException e) { return null; } switch (eventSeverity) { case ERROR: case FATAL: return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); case WARN: return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK); case INFO: case DEBUG: case TRACE: return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK); } return null; } }); }
From source file:com.aptana.ui.preferences.ProjectBuildPathPropertyPage.java
License:Open Source License
/** * getLabelProvider//from ww w. j a va 2s. com * * @return */ private IBaseLabelProvider getLabelProvider() { return new ITableLabelProvider() { public void addListener(ILabelProviderListener listener) { } public void dispose() { } public boolean isLabelProperty(Object element, String property) { return false; } public void removeListener(ILabelProviderListener listener) { } public Image getColumnImage(Object element, int columnIndex) { return null; } public String getColumnText(Object element, int columnIndex) { if (element instanceof BuildPathEntry) { BuildPathEntry entry = (BuildPathEntry) element; switch (columnIndex) { case 0: return entry.getDisplayName(); case 1: String result = entry.getPath().toString(); if (result != null && result.startsWith("file:")) //$NON-NLS-1$ { File f = new File(entry.getPath()); return f.getAbsolutePath(); } return result; } } return null; } }; }
From source file:com.cisco.yangide.ui.wizards.YangProjectWizardPage.java
License:Open Source License
/** * @param parent//from w ww .j a v a 2s .co m */ private void privateCreateGeneratorControls(Composite parent) { Label label = new Label(parent, SWT.NONE); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1)); label.setText("Source Code Generators:"); generatorsViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION); generatorsTable = generatorsViewer.getTable(); generatorsTable.setLinesVisible(true); generatorsTable.setHeaderVisible(true); generatorsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); generatorsTable.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { validate(); } }); createTableColum(generatorsTable, "Group ID", 120); createTableColum(generatorsTable, "Artifact ID", 120); createTableColum(generatorsTable, "Version", 100); createTableColum(generatorsTable, "Generator Class Name", 200); createTableColum(generatorsTable, "Output Directory", 200); generatorsViewer.setLabelProvider(new ITableLabelProvider() { @Override public void removeListener(ILabelProviderListener listener) { } @Override public boolean isLabelProperty(Object element, String property) { return false; } @Override public void dispose() { } @Override public void addListener(ILabelProviderListener listener) { } @Override public String getColumnText(Object element, int columnIndex) { if (element instanceof CodeGeneratorConfig) { CodeGeneratorConfig conf = (CodeGeneratorConfig) element; String txt = null; switch (columnIndex) { case 0: txt = conf.getGroupId(); break; case 1: txt = conf.getArtifactId(); break; case 2: txt = conf.getVersion(); break; case 3: txt = conf.getGenClassName(); break; case 4: txt = conf.getGenOutputDirectory(); break; } return txt != null ? txt : ""; } return ""; } @Override public Image getColumnImage(Object element, int columnIndex) { return null; } }); Composite group = new Composite(parent, SWT.NONE); group.setLayout(new GridLayout(1, false)); group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true)); addBtn = new Button(group, SWT.NONE); addBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); addBtn.setText("Add..."); addBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { YangCodeGeneratorDialog dialog = new YangCodeGeneratorDialog(getShell()); if (dialog.open() == Window.OK) { generatorsViewer.add(dialog.getConfig()); } } }); editBtn = new Button(group, SWT.NONE); editBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); editBtn.setText("Edit..."); editBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { CodeGeneratorConfig config = (CodeGeneratorConfig) generatorsViewer .getElementAt(generatorsTable.getSelectionIndex()); YangCodeGeneratorDialog dialog = new YangCodeGeneratorDialog(getShell(), config); if (dialog.open() == Window.OK) { generatorsViewer.update(dialog.getConfig(), null); } } }); removeBtn = new Button(group, SWT.NONE); removeBtn.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); removeBtn.setText("Remove"); removeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (generatorsTable.getSelectionCount() > 1) { generatorsTable.remove(generatorsTable.getSelectionIndices()); validate(); } } }); validate(); }
From source file:com.drgarbage.bytecode.jdi.dialogs.SelectDebugTargetDialog.java
License:Apache License
private void createDebugTargetSelectionTable(Composite parent) { tableViewer = new TableViewer(parent, SWT.BORDER); tableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { buttonPressed(OK);/*from w ww . j a v a 2s .c om*/ } }); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateEnablement(); } }); tableViewer.setContentProvider(new ArrayContentProvider()); // vmsTableViewer.setLabelProvider(new DefaultLabelProvider()); tableViewer.setLabelProvider(new ITableLabelProvider() { public void addListener(ILabelProviderListener listener) { } public void dispose() { } public Image getColumnImage(Object element, int columnIndex) { if (columnIndex == 0 && element instanceof IJavaType[]) { IJavaType[] jts = (IJavaType[]) element; if (jts.length > 0) { IJavaType firstType = jts[0]; // determine the image from the launch config type String imageKey = getImageKey(firstType.getDebugTarget().getLaunch()); if (imageKey != null) { return DebugPluginImages.getImage(imageKey); } } } return null; } public String getColumnText(Object element, int columnIndex) { if (element instanceof IJavaType[]) { IJavaType[] jts = (IJavaType[]) element; if (jts.length > 0) { IJavaType firstType = jts[0]; try { return firstType.getDebugTarget().getName(); } catch (DebugException e) { } } } return null; } private String getImageKey(ILaunch launch) { ILaunchConfiguration configuration = launch.getLaunchConfiguration(); if (configuration != null) { try { return configuration.getType().getIdentifier(); } catch (CoreException e) { BytecodeVisualizerPlugin.log(e); return null; } } // if no config, use the old "mode" way if (launch.getLaunchMode().equals(ILaunchManager.DEBUG_MODE)) { return IDebugUIConstants.IMG_OBJS_LAUNCH_DEBUG; } else if (launch.isTerminated()) { return IDebugUIConstants.IMG_OBJS_LAUNCH_RUN_TERMINATED; } else { return IDebugUIConstants.IMG_OBJS_LAUNCH_RUN; } } public boolean isLabelProperty(Object element, String property) { return false; } public void removeListener(ILabelProviderListener listener) { } }); tableViewer.addFilter(new ViewerFilter() { public boolean select(Viewer viewer, Object parentElement, Object element) { return true; } }); tableViewer.setInput(displayCandidates); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; data.heightHint = IDialogConstants.ENTRY_FIELD_WIDTH; tableViewer.getTable().setLayoutData(data); }