use of org.eclipse.jface.viewers.ISelectionChangedListener in project sling by apache.
the class JcrPropertiesView method createPartControl.
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
SyncDirManager.registerUpdateListener(new UpdateHandler() {
@Override
public void syncDirUpdated(SyncDir syncDir) {
refreshContent();
}
});
mainControl = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true);
mainControl.setLayout(gridLayout);
if (getViewSite() != null) {
titleLabel = new Label(mainControl, SWT.WRAP);
titleLabel.setText("");
GridData data = new GridData(GridData.FILL_HORIZONTAL);
titleLabel.setLayoutData(data);
Label horizontalLine = new Label(mainControl, SWT.SEPARATOR | SWT.HORIZONTAL);
data = new GridData(GridData.FILL_HORIZONTAL);
horizontalLine.setLayoutData(data);
}
Font font;
if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
/* title font is 2pt larger than that used in the tabs. */
fontData[0].setHeight(fontData[0].getHeight() + 2);
JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
}
font = JFaceResources.getFont(TITLE_FONT);
if (titleLabel != null) {
titleLabel.setFont(font);
}
Composite tableParent = new Composite(mainControl, SWT.NONE);
// tableParent.setBackground(new Color(Display.getDefault(), 100,20,180));
GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
// shrink to min - table settings will resize to correct ratios
tableLayoutData.widthHint = 1;
tableLayoutData.heightHint = SWT.DEFAULT;
tableParent.setLayoutData(tableLayoutData);
TableColumnLayout tableLayout = new TableColumnLayout() {
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
Point p = super.computeSize(composite, wHint, hHint, flushCache);
return new Point(p.x, p.y);
}
};
tableParent.setLayout(tableLayout);
viewer = new TableViewer(tableParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION);
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer), new CellNavigationStrategy());
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
resetLastValueEdited();
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
TableViewerEditor.create(viewer, focusCellManager, actSupport, features);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
viewer.setContentProvider(new ViewContentProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
final ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
if (iss.isEmpty()) {
deleteAction.setEnabled(false);
} else {
deleteAction.setEnabled(true);
}
} else {
deleteAction.setEnabled(false);
}
}
});
CellLabelProvider clp = new JcrCellLabelProvider(viewer);
TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
column0.getColumn().setText("Name");
column0.getColumn().setResizable(true);
column0.getColumn().setWidth(200);
tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(30, 140));
final TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
column1.getColumn().setText("Type");
column1.getColumn().setResizable(true);
column1.getColumn().setWidth(300);
column1.setLabelProvider(clp);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(10, 80));
final TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
column2.getColumn().setText("Value");
column2.getColumn().setResizable(true);
column2.getColumn().setWidth(300);
tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(70, 220));
final TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
column3.getColumn().setText("Protected");
column3.getColumn().setResizable(true);
column3.getColumn().setWidth(300);
column3.setLabelProvider(clp);
tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(5, 57));
final TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
column4.getColumn().setText("Mandatory");
column4.getColumn().setResizable(true);
column4.getColumn().setWidth(300);
column4.setLabelProvider(clp);
tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(5, 62));
final TableViewerColumn column5 = new TableViewerColumn(viewer, SWT.NONE);
column5.getColumn().setText("Multiple");
column5.getColumn().setResizable(true);
column5.getColumn().setWidth(300);
column5.setLabelProvider(clp);
tableLayout.setColumnData(column5.getColumn(), new ColumnWeightData(5, 82));
final TableViewerColumn column6 = new TableViewerColumn(viewer, SWT.NONE);
column6.getColumn().setText("Auto Created");
column6.getColumn().setResizable(true);
column6.getColumn().setWidth(300);
column6.setLabelProvider(clp);
tableLayout.setColumnData(column6.getColumn(), new ColumnWeightData(5, 77));
column0.setLabelProvider(clp);
column0.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.NAME));
column1.setLabelProvider(clp);
column1.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.TYPE));
column2.setLabelProvider(clp);
column2.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.VALUE));
column5.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.MULTIPLE));
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.sling.ide.eclipse-ui.viewer");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
listener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
Object firstElem = iss.getFirstElement();
if (firstElem instanceof JcrNode) {
JcrNode jcrNode = (JcrNode) firstElem;
setInput(jcrNode);
return;
}
}
}
};
if (getViewSite() != null) {
getViewSite().getPage().addSelectionListener(listener);
final ISelection selection = getViewSite().getPage().getSelection();
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
listener.selectionChanged(null, selection);
}
});
}
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project eclipse.platform.text by eclipse.
the class AnnotationsConfigurationBlock method createControl.
@Override
public Control createControl(Composite parent) {
PixelConverter pixelConverter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
Label label = new Label(composite, SWT.LEFT);
label.setText(TextEditorMessages.AnnotationsConfigurationBlock_annotationPresentationOptions);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
label.setLayoutData(gd);
Composite editorComposite = new Composite(composite, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
editorComposite.setLayout(layout);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
gd.horizontalSpan = 2;
editorComposite.setLayoutData(gd);
fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider());
fAnnotationTypeViewer.setContentProvider(new ItemContentProvider());
gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
gd.heightHint = pixelConverter.convertHeightInCharsToPixels(20);
fAnnotationTypeViewer.getControl().setLayoutData(gd);
Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
optionsComposite.setLayout(layout);
optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
label = new Label(optionsComposite, SWT.LEFT);
label.setText(TextEditorMessages.AnnotationsConfigurationBlock_labels_showIn);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalSpan = 2;
label.setLayoutData(gd);
fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
fShowInVerticalRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInVerticalRuler);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalSpan = 2;
gd.horizontalIndent = 20;
fShowInVerticalRulerCheckBox.setLayoutData(gd);
fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
fShowInOverviewRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInOverviewRuler);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalSpan = 2;
gd.horizontalIndent = 20;
fShowInOverviewRulerCheckBox.setLayoutData(gd);
fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
fShowInTextCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInText);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalIndent = 20;
fShowInTextCheckBox.setLayoutData(gd);
fDecorationViewer = new ComboViewer(optionsComposite, SWT.READ_ONLY);
fDecorationViewer.setContentProvider(new ArrayContentProvider());
fDecorationViewer.setLabelProvider(new ArrayLabelProvider());
fDecorationViewer.setComparator(new ViewerComparator(Collator.getInstance()));
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
fDecorationViewer.getControl().setLayoutData(gd);
fDecorationViewer.setInput(new Object[] { HIGHLIGHT, SQUIGGLES, BOX, DASHED_BOX, UNDERLINE, PROBLEM_UNDERLINE, IBEAM });
fDecorationViewer.getCombo().setVisibleItemCount(fDecorationViewer.getCombo().getItemCount());
label = new Label(optionsComposite, SWT.LEFT);
label.setText(TextEditorMessages.AnnotationsConfigurationBlock_color);
gd = new GridData();
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalIndent = 20;
label.setLayoutData(gd);
fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite);
Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton();
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
foregroundColorButton.setLayoutData(gd);
addFiller(optionsComposite);
fIsNextPreviousTargetCheckBox = new Button(optionsComposite, SWT.CHECK);
fIsNextPreviousTargetCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_isNavigationTarget);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment = GridData.BEGINNING;
gd.horizontalSpan = 2;
gd.horizontalIndent = 0;
fIsNextPreviousTargetCheckBox.setLayoutData(gd);
fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
handleAnnotationListSelection();
}
});
fShowInTextCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
final boolean value = fShowInTextCheckBox.getSelection();
if (value) {
// enable whatever is in the combo
String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
if (HIGHLIGHT.equals(decoration))
fStore.setValue(item.highlightKey, true);
else
fStore.setValue(item.textKey, true);
} else {
// disable both
if (item.textKey != null)
fStore.setValue(item.textKey, false);
if (item.highlightKey != null)
fStore.setValue(item.highlightKey, false);
}
fStore.setValue(item.textKey, value);
updateDecorationViewer(item, false);
fAnnotationTypeViewer.refresh(item);
}
});
fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
fIsNextPreviousTargetCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.isNextPreviousNavigationKey, fIsNextPreviousTargetCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
foregroundColorButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
fAnnotationTypeViewer.refresh(item);
}
});
fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
ListItem item = getSelectedItem();
if (fShowInTextCheckBox.getSelection()) {
if (HIGHLIGHT.equals(decoration)) {
fStore.setValue(item.highlightKey, true);
if (item.textKey != null) {
fStore.setValue(item.textKey, false);
if (item.textStyleKey != null)
fStore.setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE);
}
} else {
if (item.highlightKey != null)
fStore.setValue(item.highlightKey, false);
if (item.textKey != null) {
fStore.setValue(item.textKey, true);
if (item.textStyleKey != null)
fStore.setValue(item.textStyleKey, decoration[1]);
}
}
}
fAnnotationTypeViewer.refresh(item);
}
});
composite.layout();
return composite;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project eclipse.platform.text by eclipse.
the class AbstractTextSearchViewPage method createViewer.
private void createViewer(Composite parent, int layout) {
if ((layout & FLAG_LAYOUT_FLAT) != 0) {
TableViewer viewer = createTableViewer(parent);
fViewer = viewer;
configureTableViewer(viewer);
} else if ((layout & FLAG_LAYOUT_TREE) != 0) {
TreeViewer viewer = createTreeViewer(parent);
fViewer = viewer;
configureTreeViewer(viewer);
fCollapseAllAction.setViewer(viewer);
fExpandAllAction.setViewer(viewer);
}
fCopyToClipboardAction.setViewer(fViewer);
fSelectAllAction.setViewer(fViewer);
IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
tbm.removeAll();
SearchView.createToolBarGroups(tbm);
fillToolbar(tbm);
tbm.update(false);
new OpenAndLinkWithEditorHelper(fViewer) {
@Override
protected void activate(ISelection selection) {
final int currentMode = OpenStrategy.getOpenMethod();
try {
OpenStrategy.setOpenMethod(OpenStrategy.DOUBLE_CLICK);
handleOpen(new OpenEvent(fViewer, selection));
} finally {
OpenStrategy.setOpenMethod(currentMode);
}
}
@Override
protected void linkToEditor(ISelection selection) {
// not supported by this part
}
@Override
protected void open(ISelection selection, boolean activate) {
handleOpen(new OpenEvent(fViewer, selection));
}
};
fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
fCurrentMatchIndex = -1;
fRemoveSelectedMatches.setEnabled(canRemoveMatchesWith(event.getSelection()));
}
});
fViewer.addSelectionChangedListener(fViewerAdapter);
Menu menu = fMenu.createContextMenu(fViewer.getControl());
fViewer.getControl().setMenu(menu);
updateLayoutActions();
getViewPart().updateLabel();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project eclipse.platform.text by eclipse.
the class MatchFilterSelectionDialog method createMatchFilterControls.
private void createMatchFilterControls(Composite parent) {
// Create list viewer
Label l = new Label(parent, SWT.NONE);
l.setFont(parent.getFont());
l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
table.setFont(parent.getFont());
fListViewer = new CheckboxTableViewer(table);
GridData data = new GridData(GridData.FILL_BOTH);
data.minimumHeight = convertHeightInCharsToPixels(8);
table.setLayoutData(data);
class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {
@Override
public void selectionChanged(SelectionChangedEvent event) {
performFilterListSelectionChanged();
}
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
performFilterListCheckStateChanged();
}
@Override
public String getText(Object element) {
return ((MatchFilter) element).getName();
}
}
ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
fListViewer.setLabelProvider(listenerAndLP);
fListViewer.setContentProvider(new ArrayContentProvider());
fListViewer.addSelectionChangedListener(listenerAndLP);
fListViewer.addCheckStateListener(listenerAndLP);
fListViewer.setInput(fAllFilters);
fListViewer.setCheckedElements(fEnabledFilters);
l = new Label(parent, SWT.NONE);
l.setFont(parent.getFont());
l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
fDescription.setFont(parent.getFont());
data = new GridData(GridData.FILL_HORIZONTAL);
data.heightHint = convertHeightInCharsToPixels(3);
fDescription.setLayoutData(data);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method getSelectionChangedListener.
/**
* Returns this editor's selection changed listener to be installed
* on the editor's source viewer.
*
* @return the listener
*/
protected final ISelectionChangedListener getSelectionChangedListener() {
if (fSelectionChangedListener == null) {
fSelectionChangedListener = new ISelectionChangedListener() {
private Runnable fRunnable = new Runnable() {
@Override
public void run() {
// check whether editor has not been disposed yet
if (fSourceViewer != null && fSourceViewer.getDocument() != null) {
handleCursorPositionChanged();
updateSelectionDependentActions();
}
}
};
private Display fDisplay;
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (fDisplay == null)
fDisplay = getSite().getShell().getDisplay();
if (Display.getCurrent() == fDisplay)
fRunnable.run();
else
fDisplay.asyncExec(fRunnable);
}
};
}
return fSelectionChangedListener;
}
Aggregations