use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class MenuEntryDialog method createDialogArea.
@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;
// 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);
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
iconPathText = new FileSelectWidget(composite, "", new String[] { "*.png", "*.gif", "*.jpg" }, "", true);
// 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();
}
// $NON-NLS-1$
return "";
}
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) {
// $NON-NLS-1$
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());
descriptionsViewer.setInput(descriptionsMap);
}
idText.setFocus();
return composite;
}
use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class ViewBrowserMainPage method createCharacteristicsContent.
@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite charComposite) {
try {
Label vbeLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_ViewableElements, SWT.NULL);
vbeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
Label sbeLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_SearchableElements, SWT.NULL);
sbeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
viewableBEsList = new List(charComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
viewableBEsList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) viewableBEsList.getLayoutData()).heightHint = 100;
searchableBEsList = new List(charComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
searchableBEsList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) searchableBEsList.getLayoutData()).heightHint = 100;
Label wcLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_Conditions, SWT.NULL);
wcLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1));
wcListViewer = new ListViewer(charComposite, SWT.BORDER);
wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 100;
wcListViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
return ((WSView) inputElement).getWhereConditions().toArray();
}
});
wcListViewer.setLabelProvider(new ILabelProvider() {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
WSWhereCondition wc = (WSWhereCondition) element;
// $NON-NLS-1$
String text = wc.getLeftPath() + " ";
if (wc.getOperator().equals(WSWhereOperator.CONTAINS)) {
// $NON-NLS-1$
text += "Contains";
} else if (wc.getOperator().equals(WSWhereOperator.CONTAINS_SENTENCE)) {
// $NON-NLS-1$
text += "contains the sentence";
} else if (wc.getOperator().equals(WSWhereOperator.EQUALS)) {
// $NON-NLS-1$
text += "=";
} else if (wc.getOperator().equals(WSWhereOperator.GREATER_THAN)) {
// $NON-NLS-1$
text += ">";
} else if (wc.getOperator().equals(WSWhereOperator.GREATER_THAN_OR_EQUAL)) {
// $NON-NLS-1$
text += ">=";
} else if (wc.getOperator().equals(WSWhereOperator.JOIN)) {
// $NON-NLS-1$
text += "Joins With";
} else if (wc.getOperator().equals(WSWhereOperator.LOWER_THAN)) {
// $NON-NLS-1$
text += "<";
} else if (wc.getOperator().equals(WSWhereOperator.LOWER_THAN_OR_EQUAL)) {
// $NON-NLS-1$
text += "<=";
} else if (wc.getOperator().equals(WSWhereOperator.NOT_EQUALS)) {
// $NON-NLS-1$
text += "!=";
} else if (wc.getOperator().equals(WSWhereOperator.STARTSWITH)) {
// $NON-NLS-1$
text += "Starts With";
} else if (wc.getOperator().equals(WSWhereOperator.EMPTY_NULL)) {
// $NON-NLS-1$
text += "Is Empty Or Null";
} else if (wc.getOperator().equals(WSWhereOperator.FULLTEXTSEARCH)) {
// $NON-NLS-1$
text += "whole content contains";
}
// $NON-NLS-1$
text += " ";
if (!wc.getOperator().equals(WSWhereOperator.JOIN)) {
// $NON-NLS-1$
text += "\"";
}
text += wc.getRightValueOrPath();
if (!wc.getOperator().equals(WSWhereOperator.JOIN)) {
// $NON-NLS-1$
text += "\"";
}
// $NON-NLS-1$
text += " ";
if (wc.getStringPredicate().equals(WSStringPredicate.AND)) {
// $NON-NLS-1$
text += "[and]";
} else if (wc.getStringPredicate().equals(WSStringPredicate.NONE)) {
// $NON-NLS-1$
text += "";
} else if (wc.getStringPredicate().equals(WSStringPredicate.OR)) {
// $NON-NLS-1$
text += "[or]";
} else if (wc.getStringPredicate().equals(WSStringPredicate.NOT)) {
// $NON-NLS-1$
text += "[not]";
}
return text;
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
int columns = 6;
Composite resultsGroup = this.getNewSectionComposite(Messages.ViewBrowserMainPage_SearchAndResults);
resultsGroup.setLayout(new GridLayout(columns, false));
Composite createComposite = toolkit.createComposite(resultsGroup);
GridLayout layout = new GridLayout(3, false);
layout.marginWidth = 0;
createComposite.setLayout(layout);
createComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
Label containerLabel = toolkit.createLabel(createComposite, Messages.ViewBrowserMainPage_Container, SWT.NULL);
containerLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
dataClusterCombo = new Combo(createComposite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
dataClusterCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
((GridData) dataClusterCombo.getLayoutData()).minimumWidth = 100;
clusterTypeCombo = new Combo(createComposite, SWT.READ_ONLY | SWT.SINGLE);
GridData typeLayout = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
typeLayout.horizontalIndent = 10;
clusterTypeCombo.setLayoutData(typeLayout);
Label searchOnLabel = toolkit.createLabel(resultsGroup, Messages.ViewBrowserMainPage_SearchOn, SWT.NULL);
GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
layoutData.horizontalIndent = 20;
searchOnLabel.setLayoutData(layoutData);
searchItemCombo = new Combo(resultsGroup, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
searchItemCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
((GridData) searchItemCombo.getLayoutData()).minimumWidth = 100;
searchItemCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (FULL_TEXT.equals(searchItemCombo.getText())) {
matchAllWordsBtn.setEnabled(true);
} else {
matchAllWordsBtn.setSelection(false);
matchAllWordsBtn.setEnabled(false);
}
}
});
// $NON-NLS-1$
searchText = toolkit.createText(resultsGroup, "", SWT.BORDER);
searchText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
searchText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.stateMask == 0) && (e.character == SWT.CR)) {
ViewBrowserMainPage.this.resultsViewer.setInput(getResults());
}
}
});
Button bSearch = toolkit.createButton(resultsGroup, Messages.ViewBrowserMainPage_Search, SWT.CENTER);
bSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
bSearch.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
ViewBrowserMainPage.this.resultsViewer.setInput(getResults());
}
});
matchAllWordsBtn = toolkit.createButton(resultsGroup, Messages.ViewBrowserMainPage_MatchWholeSentence, SWT.CHECK);
matchAllWordsBtn.setSelection(true);
// $NON-NLS-1$
resultsLabel = toolkit.createLabel(resultsGroup, "", SWT.NULL);
GridData resultLayoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, columns - 1, 1);
resultLayoutData.widthHint = 100;
resultsLabel.setLayoutData(resultLayoutData);
resultsViewer = new TableViewer(resultsGroup);
resultsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
((GridData) resultsViewer.getControl().getLayoutData()).heightHint = 500;
resultsViewer.setContentProvider(new ArrayContentProvider());
resultsViewer.setLabelProvider(new XMLTableLabelProvider());
resultsViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
resultsViewer.setSelection(event.getSelection());
try {
new DOMViewAction(ViewBrowserMainPage.this.getSite().getShell(), resultsViewer).run();
} catch (Exception e) {
MessageDialog.openError(ViewBrowserMainPage.this.getSite().getShell(), Messages._Error, Messages.bind(Messages.ViewBrowserMainPage_ErrorMsg, e.getClass().getName(), e.getLocalizedMessage()));
}
}
});
hookContextMenu();
addListener();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class ItemsTrashBrowserMainPage method createFormContent.
@Override
protected void createFormContent(IManagedForm managedForm) {
try {
// sets the title
managedForm.getForm().setText(this.getTitle());
// get the toolkit
FormToolkit toolkit = managedForm.getToolkit();
// get the body
Composite composite = managedForm.getForm().getBody();
composite.setLayout(new GridLayout(9, false));
/**
* Search Text
*/
Label descriptionLabel = toolkit.createLabel(composite, Messages.ItemsTrashBrowserMainPage_1, SWT.NULL);
descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
// $NON-NLS-1$
searchText = toolkit.createText(composite, "*", SWT.BORDER);
searchText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
// searchText.addModifyListener(this);
searchText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.stateMask == 0) && (e.character == SWT.CR)) {
ItemsTrashBrowserMainPage.this.resultsViewer.setInput(getResults(true));
ItemsTrashBrowserMainPage.this.resultsViewer.getTable().setFocus();
}
}
});
// search
// $NON-NLS-1$
Button bSearch = toolkit.createButton(composite, "", SWT.CENTER);
bSearch.setImage(ImageCache.getCreatedImage(EImage.BROWSE.getPath()));
bSearch.setToolTipText(Messages.ItemsTrashBrowserMainPage_2);
bSearch.setLayoutData(new GridData(SWT.NONE, SWT.CENTER, false, false, 1, 1));
bSearch.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
ItemsTrashBrowserMainPage.this.resultsViewer.setInput(getResults(true));
}
});
/**
* Create Table
*/
final Table table = createTable(composite);
resultsViewer = new TableViewer(table);
resultsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 9, 1));
((GridData) resultsViewer.getControl().getLayoutData()).heightHint = 500;
resultsViewer.setContentProvider(new ArrayContentProvider());
resultsViewer.setLabelProvider(new ClusterTableLabelProvider());
resultsViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
resultsViewer.setSelection(event.getSelection());
try {
new DisplayDroppedItemAction(ItemsTrashBrowserMainPage.this.getSite().getShell(), resultsViewer).run();
} catch (Exception e) {
MessageDialog.openError(ItemsTrashBrowserMainPage.this.getSite().getShell(), Messages._Error, Messages.ItemsTrashBrowserMainPage_4 + e.getClass().getName() + Messages.ItemsTrashBrowserMainPage_5 + e.getLocalizedMessage());
}
}
});
hookKeyboard();
hookContextMenu();
// nothng will show on the form if not called
managedForm.reflow(true);
searchText.setFocus();
// adapt body add mouse/focus listener for child
WidgetFactory factory = WidgetFactory.getWidgetFactory();
factory.adapt(managedForm.getForm().getBody());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class WidgetUtils method initRedoUndo.
public static void initRedoUndo(final TextViewer viewer) {
TextViewerUndoManager undoManager = new TextViewerUndoManager(20);
undoManager.connect(viewer);
viewer.setUndoManager(undoManager);
StyledText styledText = viewer.getTextWidget();
styledText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
private boolean isUndoKeyPress(KeyEvent e) {
// CTRL + z
return (e.keyCode == 'z' && e.stateMask == SWT.CTRL);
}
private boolean isRedoKeyPress(KeyEvent e) {
// CTRL + y
return (e.keyCode == 'y' && e.stateMask == SWT.CTRL);
}
public void keyReleased(KeyEvent e) {
if (isUndoKeyPress(e)) {
viewer.doOperation(ITextOperationTarget.UNDO);
} else if (isRedoKeyPress(e)) {
viewer.doOperation(ITextOperationTarget.REDO);
}
}
});
// undoManager.getUndoContext();
}
use of org.eclipse.swt.events.KeyListener in project tmdm-studio-se by Talend.
the class TisTableViewer method createViewer.
@Override
protected void createViewer() {
super.createTable();
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 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, false, 1, 1));
GridLayout layout = new GridLayout(8, false);
layout.marginTop = 0;
layout.marginBottom = 0;
layout.marginHeight = 0;
stepUpDownComposite.setLayout(layout);
//
// $NON-NLS-1$
addButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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()) {
// $NON-NLS-1$
Button selNewPathButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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();
// $NON-NLS-1$
String[] xpaths = xpathDialog.getXpath().split("&");
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();
}
}
});
}
// $NON-NLS-1$
deleteButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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
// $NON-NLS-1$
Button deleteAllButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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()));
// $NON-NLS-1$
upButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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();
}
}
});
// $NON-NLS-1$
downButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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();
}
}
});
// $NON-NLS-1$
copyButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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);
}
}
});
// $NON-NLS-1$
pastButton = toolkit.createButton(stepUpDownComposite, "", SWT.PUSH | SWT.CENTER);
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;
}
}
}
// $NON-NLS-1$
return "";
}
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);
}
});
}
Aggregations