use of org.eclipse.jface.viewers.SelectionChangedEvent in project yamcs-studio by yamcs.
the class SpreadSheetTable method addSelectionChangedListener.
/**
*Add a selection changed listener. Call whenever selection of the table changes.
* @param listener the listener
*/
public void addSelectionChangedListener(ITableSelectionChangedListener listener) {
if (selectionChangedListeners == null) {
selectionChangedListeners = new ListenerList();
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
String[][] selection = getSelection();
for (Object listener : selectionChangedListeners.getListeners()) {
((ITableSelectionChangedListener) listener).selectionChanged(selection);
}
}
});
}
selectionChangedListeners.add(listener);
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project yamcs-studio by yamcs.
the class ActionsInputDialog method createActionsTableViewer.
/**
* Creates and configures a {@link TableViewer}.
*
* @param parent
* The parent for the table
* @return The {@link TableViewer}
*/
private TableViewer createActionsTableViewer(final Composite parent) {
TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.SINGLE);
viewer.setContentProvider(new BaseWorkbenchContentProvider() {
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(final Object element) {
return (((List<AbstractWidgetAction>) element).toArray());
}
});
viewer.setLabelProvider(new WorkbenchLabelProvider() {
@Override
protected String decorateText(String input, Object element) {
return input + "(index: " + actionsList.indexOf(element) + ")";
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent event) {
refreshGUIOnSelection();
}
});
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
return viewer;
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project yamcs-studio by yamcs.
the class RuleDataEditDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
final Composite parent_Composite = (Composite) super.createDialogArea(parent);
// Parent composite has GridLayout with 1 columns.
// Create embedded composite w/ 2 columns
final Composite mainComposite = new Composite(parent_Composite, SWT.None);
mainComposite.setLayout(new GridLayout(2, false));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint = 500;
mainComposite.setLayoutData(gridData);
final Composite topComposite = new Composite(mainComposite, SWT.None);
topComposite.setLayout(new GridLayout(2, false));
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.horizontalSpan = 2;
topComposite.setLayoutData(gd);
createLabel(topComposite, "Rule Name: ");
nameText = new Text(topComposite, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
nameText.setText(ruleData.getName());
nameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
ruleData.setName(nameText.getText());
}
});
createLabel(topComposite, "Property: ");
propCombo = new Combo(topComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
propCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
String[] comboItems = new String[propIDList.size()];
int i = 0;
for (String id : propIDList) {
comboItems[i++] = ruleData.getWidgetModel().getProperty(id).getDescription() + " (" + id + // $NON-NLS-1$ //$NON-NLS-2$
")";
}
propCombo.setItems(comboItems);
propCombo.select(propIDList.indexOf(ruleData.getPropId()));
propCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (propIDList.get(propCombo.getSelectionIndex()).equals(AbstractPVWidgetModel.PROP_PVVALUE)) {
MessageDialog.openWarning(propCombo.getShell(), "Warning", "Note: Changing pv_value property with rule or " + "script will not write value to the PV. " + "It only change the graphical value on the widget! " + "If you need to write a PV, please call PV.setValue() from script.");
}
ruleData.setPropId(propIDList.get(propCombo.getSelectionIndex()));
if (ruleData.getProperty().getPropertyDescriptor() == null || ruleData.getProperty().onlyAcceptExpressionInRule()) {
ruleData.setOutputExpValue(true);
outPutExpButton.setSelection(true);
outPutExpButton.setEnabled(false);
for (Expression exp : expressionList) // $NON-NLS-1$
exp.setValue("");
valueColumn.getColumn().setText("Output Expression");
} else
outPutExpButton.setEnabled(true);
if (!ruleData.isOutputExpValue()) {
for (Expression exp : expressionList) exp.setValue(ruleData.isOutputExpValue() ? "" : // $NON-NLS-1$
ruleData.getProperty().getDefaultValue());
}
expressionViewer.refresh();
}
});
outPutExpButton = new Button(topComposite, SWT.CHECK);
gd = new GridData();
gd.horizontalSpan = 2;
outPutExpButton.setLayoutData(gd);
outPutExpButton.setText("Output Expression");
if (ruleData.getProperty().getPropertyDescriptor() == null || ruleData.getProperty().onlyAcceptExpressionInRule()) {
ruleData.setOutputExpValue(true);
outPutExpButton.setEnabled(false);
}
outPutExpButton.setSelection(ruleData.isOutputExpValue());
outPutExpButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ruleData.setOutputExpValue(outPutExpButton.getSelection());
for (Expression exp : expressionList) exp.setValue(ruleData.isOutputExpValue() ? "" : // $NON-NLS-1$
ruleData.getProperty().getDefaultValue());
valueColumn.getColumn().setText(ruleData.isOutputExpValue() ? "Output Expression" : "Output Value");
expressionViewer.refresh();
}
});
// Left Panel: List of scripts
final Composite leftComposite = new Composite(mainComposite, SWT.NONE);
leftComposite.setLayout(new GridLayout(1, false));
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 350;
leftComposite.setLayoutData(gd);
createLabel(leftComposite, "Expressions");
Composite toolBarComposite = new Composite(leftComposite, SWT.BORDER);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginLeft = 0;
gridLayout.marginRight = 0;
gridLayout.marginBottom = 0;
gridLayout.marginTop = 0;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
toolBarComposite.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
toolBarComposite.setLayoutData(gd);
ToolBarManager toolbarManager = new ToolBarManager(SWT.FLAT);
ToolBar toolBar = toolbarManager.createControl(toolBarComposite);
GridData grid = new GridData();
grid.horizontalAlignment = GridData.FILL;
grid.verticalAlignment = GridData.BEGINNING;
toolBar.setLayoutData(grid);
createActions();
toolbarManager.add(addAction);
toolbarManager.add(copyAction);
toolbarManager.add(removeAction);
toolbarManager.add(moveUpAction);
toolbarManager.add(moveDownAction);
toolbarManager.update(true);
expressionViewer = createExpressionsTableViewer(toolBarComposite);
expressionViewer.setInput(expressionList);
expressionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
refreshActionBarOnSelection();
}
});
// Right panel: Input PVs for selected script
final Composite rightComposite = new Composite(mainComposite, SWT.NONE);
gridLayout = new GridLayout(1, false);
rightComposite.setLayout(gridLayout);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
// Account for the StringTableEditor's minimum size
gd.minimumWidth = 250;
rightComposite.setLayoutData(gd);
this.createLabel(rightComposite, "Input PVs");
pvsEditor = new PVTupleTableEditor(rightComposite, ruleData.getPVList(), SWT.BORDER);
pvsEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
if (expressionList.size() > 0)
setExpressionViewerSelection(expressionList.get(0));
final Composite bottomComposite = new Composite(mainComposite, SWT.None);
bottomComposite.setLayout(new GridLayout(1, false));
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.horizontalSpan = 2;
bottomComposite.setLayoutData(gd);
Button generateScriptButton = new Button(bottomComposite, SWT.PUSH);
generateScriptButton.setText("See Generated Script");
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
generateScriptButton.setLayoutData(gd);
final Text scriptText = new Text(bottomComposite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
scriptText.setLayoutData(gd);
generateScriptButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
scriptText.setText(ruleData.generateScript());
}
});
return parent_Composite;
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project translationstudio8 by heartsome.
the class KeysPreferencePage method createTree.
private void createTree(Composite parent) {
fPatternFilter = new CategoryPatternFilter(true, fDefaultCategory);
fPatternFilter.filterCategories(true);
GridData gridData;
fFilteredTree = new CategoryFilterTree(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION, fPatternFilter);
final GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
fFilteredTree.setLayout(layout);
gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
fFilteredTree.setLayoutData(gridData);
viewer = fFilteredTree.getViewer();
// Make sure the filtered tree has a height of ITEMS_TO_SHOW
final Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
final Object layoutData = tree.getLayoutData();
if (layoutData instanceof GridData) {
gridData = (GridData) layoutData;
final int itemHeight = tree.getItemHeight();
if (itemHeight > 1) {
gridData.heightHint = ITEMS_TO_SHOW * itemHeight;
}
}
BindingModelComparator comparator = new BindingModelComparator();
comparator.setSortColumn(2);
viewer.setComparator(comparator);
final TreeColumn commandNameColumn = new TreeColumn(tree, SWT.LEFT, COMMAND_NAME_COLUMN);
commandNameColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.commandNameColumn"));
tree.setSortColumn(commandNameColumn);
tree.setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
commandNameColumn.addSelectionListener(new ResortColumn(comparator, commandNameColumn, viewer, COMMAND_NAME_COLUMN));
final TreeViewerColumn triggerSequenceColumn = new TreeViewerColumn(viewer, SWT.LEFT, KEY_SEQUENCE_COLUMN);
triggerSequenceColumn.getColumn().setText(Messages.getString("preferencepage.KeysPreferencePage.triggerSequenceColumn"));
triggerSequenceColumn.getColumn().addSelectionListener(new ResortColumn(comparator, triggerSequenceColumn.getColumn(), viewer, KEY_SEQUENCE_COLUMN));
triggerSequenceColumn.setEditingSupport(new TableViewerEditingSupport(viewer, 1));
final TreeColumn categoryColumn = new TreeColumn(tree, SWT.LEFT, CATEGORY_COLUMN);
categoryColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.categoryColumn"));
categoryColumn.addSelectionListener(new ResortColumn(comparator, categoryColumn, viewer, CATEGORY_COLUMN));
viewer.setContentProvider(new ModelContentProvider());
viewer.setLabelProvider(new BindingElementLabelProvider());
fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true);
final TreeColumn[] columns = viewer.getTree().getColumns();
columns[COMMAND_NAME_COLUMN].setWidth(240);
columns[KEY_SEQUENCE_COLUMN].setWidth(130);
columns[CATEGORY_COLUMN].setWidth(130);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
// When the viewer changes selection, update the model's current
// selection
public void selectionChanged(SelectionChangedEvent event) {
changeBackground();
ModelElement binding = (ModelElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
model.setSelectedElement(binding);
}
});
IPropertyChangeListener treeUpdateListener = new IPropertyChangeListener() {
// When the model changes a property, update the viewer
public void propertyChange(PropertyChangeEvent event) {
if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
Object newVal = event.getNewValue();
StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(newVal);
viewer.setSelection(structuredSelection, true);
} else if (event.getSource() instanceof BindingElement && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
viewer.update(event.getSource(), null);
} else if (BindingElement.PROP_CONFLICT.equals(event.getProperty())) {
viewer.update(event.getSource(), null);
} else if (BindingModel.PROP_BINDINGS.equals(event.getProperty())) {
// viewer.refresh();
} else if (BindingModel.PROP_BINDING_ADD.equals(event.getProperty())) {
viewer.add(model, event.getNewValue());
} else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
viewer.remove(event.getNewValue());
} else if (BindingModel.PROP_BINDING_FILTER.equals(event.getProperty())) {
// viewer.refresh();
}
changeBackground();
// isValid();
}
};
keyController.addPropertyChangeListener(treeUpdateListener);
// IPropertyChangeListener conflictsListener = new IPropertyChangeListener() {
// public void propertyChange(PropertyChangeEvent event) {
// // System.out.println(event.getNewValue().getClass());
// if (keyController.getConflictModel().getConflicts() != null) {
// if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
// // lstConflict.clear();
// if (event.getNewValue() != null) {
// lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
// }
// // conflictViewer.setInput(event.getNewValue());
// } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
// if (event.getNewValue() != null) {
// lstConflict.add(event.getNewValue());
// }
// // conflictViewer.add(event.getNewValue());
// } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
// // conflictViewer.remove(event.getNewValue());
// if (event.getNewValue() != null) {
// lstConflict.remove(event.getNewValue());
// }
// }
// } else {
// lstConflict.clear();
// }
// // if (event.getSource() == keyController.getConflictModel()
// // && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
// // if (keyController.getConflictModel().getConflicts() != null) {
// // Object newVal = event.getNewValue();
// // StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(
// // newVal);
// // // conflictViewer.setSelection(structuredSelection, true);
// // }
// // } else if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
// // // lstConflict.clear();
// // if (event.getNewValue() != null) {
// // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
// // }
// // // conflictViewer.setInput(event.getNewValue());
// // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
// // if (event.getNewValue() != null) {
// // lstConflict.clear();
// // lstConflict.add(event.getNewValue());
// // }
// // // conflictViewer.add(event.getNewValue());
// // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
// // // conflictViewer.remove(event.getNewValue());
// // if (event.getNewValue() != null) {
// // lstConflict.clear();
// // lstConflict.remove(event.getNewValue());
// // }
// // }
// }
// };
// keyController.addPropertyChangeListener(conflictsListener);
IPropertyChangeListener dataUpdateListener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
BindingElement bindingElement = null;
boolean weCare = false;
if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
bindingElement = (BindingElement) event.getNewValue();
weCare = true;
} else if (event.getSource() == model.getSelectedElement() && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
bindingElement = (BindingElement) event.getSource();
weCare = true;
}
if (bindingElement == null && weCare) {
//$NON-NLS-1$
fBindingText.setText("");
} else if (bindingElement != null) {
KeySequence trigger = (KeySequence) bindingElement.getTrigger();
fKeySequenceText.setKeySequence(trigger);
}
}
};
keyController.addPropertyChangeListener(dataUpdateListener);
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project translationstudio8 by heartsome.
the class ProjectSettingDialog method addListeners.
protected void addListeners(final TreeViewer viewer) {
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
private void handleError() {
try {
// remove the listener temporarily so that the events caused
// by the error handling dont further cause error handling
// to occur.
viewer.removePostSelectionChangedListener(this);
// select Current PageAgain;
if (lastSuccessfulNode == null) {
return;
}
getTreeViewer().setSelection(new StructuredSelection(lastSuccessfulNode));
getCurrentPage().setVisible(true);
// clear Selected Node
setSelectedNodePreference(null);
} finally {
viewer.addPostSelectionChangedListener(this);
}
}
public void selectionChanged(SelectionChangedEvent event) {
final Object selection = getSingleSelection(event.getSelection());
if (selection instanceof IPreferenceNode) {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
if (!isCurrentPageValid()) {
handleError();
} else if (!showPage((IPreferenceNode) selection)) {
// Page flipping wasn't successful
handleError();
} else {
// Everything went well
lastSuccessfulNode = (IPreferenceNode) selection;
}
}
});
}
}
});
((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(final SelectionEvent event) {
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
return;
}
IPreferenceNode singleSelection = getSingleSelection(selection);
boolean expanded = viewer.getExpandedState(singleSelection);
viewer.setExpandedState(singleSelection, !expanded);
}
});
// Register help listener on the tree to use context sensitive help
viewer.getControl().addHelpListener(new HelpListener() {
public void helpRequested(HelpEvent event) {
if (getCurrentPage() == null) {
// no current page? open dialog's help
openDialogHelp();
return;
}
// A) A typical path: the current page has registered its own help link
// via WorkbenchHelpSystem#setHelp(). When just call it and let
// it handle the help request.
Control pageControl = getCurrentPage().getControl();
if (pageControl != null && pageControl.isListening(SWT.Help)) {
getCurrentPage().performHelp();
return;
}
// B) Less typical path: no standard listener has been created for the page.
// In this case we may or may not have an override of page's #performHelp().
// 1) Try to get default help opened for the dialog;
openDialogHelp();
// 2) Next call currentPage's #performHelp(). If it was overridden, it might switch help
// to something else.
getCurrentPage().performHelp();
}
private void openDialogHelp() {
if (getPageContainer() == null)
return;
for (Control currentControl = getPageContainer(); currentControl != null; currentControl = currentControl.getParent()) {
if (currentControl.isListening(SWT.Help)) {
currentControl.notifyListeners(SWT.Help, new Event());
break;
}
}
}
});
}
Aggregations