use of org.eclipse.jface.viewers.ICheckStateListener in project eclipse.platform.text by eclipse.
the class HyperlinkDetectorsConfigurationBlock method createControl.
@Override
public Control createControl(Composite parent) {
PixelConverter pixelConverter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
addFiller(composite, 2);
String label = TextEditorMessages.HyperlinksEnabled_label;
fHyperlinksEnabledCheckBox = addCheckBox(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED, 0);
fHyperlinksEnabledCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean state = fHyperlinksEnabledCheckBox.getSelection();
fHyperlinkDefaultKeyModifierText.setEnabled(state);
fHyperlinkKeyModifierText.setEnabled(state && getSelectedItem() != null);
fHyperlinkDetectorsViewer.getTable().setEnabled(state);
handleHyperlinkKeyModifierModified();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// Text field for default modifier string
label = TextEditorMessages.HyperlinkDefaultKeyModifier_label;
fHyperlinkDefaultKeyModifierText = (Text) addTextField(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, 15, 20, pixelConverter)[1];
fHyperlinkDefaultKeyModifierText.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
@Override
public void keyPressed(KeyEvent e) {
isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
@Override
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
// && e.time -time < 1000) {
String modifierString = fHyperlinkDefaultKeyModifierText.getText();
Point selection = fHyperlinkDefaultKeyModifierText.getSelection();
int i = selection.x - 1;
while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
i = selection.y;
while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
else if (needsPrefixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
else if (needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
else
insertString = Action.findModifierString(e.stateMask);
fHyperlinkDefaultKeyModifierText.insert(insertString);
}
}
});
fHyperlinkDefaultKeyModifierText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
handleHyperlinkDefaultKeyModifierModified();
}
});
addFiller(composite, 2);
Composite editorComposite = new Composite(composite, SWT.NONE);
GridData gd;
gd = new GridData(SWT.FILL, SWT.TOP, true, false);
gd.horizontalSpan = 2;
gd.horizontalIndent = 20;
editorComposite.setLayoutData(gd);
TableColumnLayout tableColumnlayout = new TableColumnLayout();
editorComposite.setLayout(tableColumnlayout);
// Hyperlink detector table
Table hyperlinkDetectorTable = new Table(editorComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
hyperlinkDetectorTable.setHeaderVisible(true);
hyperlinkDetectorTable.setLinesVisible(true);
hyperlinkDetectorTable.setFont(parent.getFont());
hyperlinkDetectorTable.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
handleListSelection();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
ColumnLayoutData columnLayoutData = new ColumnWeightData(1);
TableColumn nameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 0);
nameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_nameColumn);
tableColumnlayout.setColumnData(nameColumn, columnLayoutData);
TableColumn modifierKeysColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 1);
modifierKeysColumn.setText(TextEditorMessages.HyperlinkDetectorTable_modifierKeysColumn);
tableColumnlayout.setColumnData(modifierKeysColumn, columnLayoutData);
TableColumn targetNameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 2);
targetNameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_targetNameColumn);
tableColumnlayout.setColumnData(targetNameColumn, columnLayoutData);
fHyperlinkDetectorsViewer = new CheckboxTableViewer(hyperlinkDetectorTable);
fHyperlinkDetectorsViewer.setUseHashlookup(true);
fHyperlinkDetectorsViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
String id = ((ListItem) event.getElement()).id;
if (id == null)
return;
fStore.setValue(id, !event.getChecked());
}
});
fHyperlinkDetectorsViewer.setLabelProvider(new ItemLabelProvider());
fHyperlinkDetectorsViewer.setContentProvider(new ItemContentProvider());
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.heightHint = pixelConverter.convertHeightInCharsToPixels(10);
fHyperlinkDetectorsViewer.getControl().setLayoutData(gd);
// addFiller(composite, 2);
// Text field for modifier string
label = TextEditorMessages.HyperlinkKeyModifier_label;
fHyperlinkKeyModifierText = (Text) addTextField(composite, label, null, 15, 20, pixelConverter)[1];
fHyperlinkKeyModifierText.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
@Override
public void keyPressed(KeyEvent e) {
isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
@Override
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
// && e.time -time < 1000) {
String modifierString = fHyperlinkKeyModifierText.getText();
Point selection = fHyperlinkKeyModifierText.getSelection();
int i = selection.x - 1;
while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
i = selection.y;
while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
else if (needsPrefixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
else if (needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
else
insertString = Action.findModifierString(e.stateMask);
fHyperlinkKeyModifierText.insert(insertString);
}
}
});
fHyperlinkKeyModifierText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
handleHyperlinkKeyModifierModified();
}
});
return composite;
}
use of org.eclipse.jface.viewers.ICheckStateListener in project linuxtools by eclipse.
the class CheckboxTreeAndListGroup method notifyCheckStateChangeListeners.
/**
* Notify all checked state listeners that the passed element has had its
* checked state changed to the passed state
*/
protected void notifyCheckStateChangeListeners(final CheckStateChangedEvent event) {
Object[] array = getListeners();
for (int i = 0; i < array.length; i++) {
final ICheckStateListener l = (ICheckStateListener) array[i];
SafeRunner.run(new SafeRunnable() {
@Override
public void run() {
l.checkStateChanged(event);
}
});
}
}
use of org.eclipse.jface.viewers.ICheckStateListener in project linuxtools by eclipse.
the class ContainerFileSelectionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// page group
Composite composite = (Composite) super.createDialogArea(parent);
createMessageArea(composite);
// Create a fake parent of the root to be the dialog input element.
// Use an empty label so that display of the element's full name
// doesn't include a confusing label
// $NON-NLS-1$
FileSystemElement input = new FileSystemElement("", null, true);
input.addChild(root);
root.setParent(input);
selectionGroup = new CheckboxTreeAndListGroup(composite, input, getFolderProvider(), getDynamicFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, // since this page has no other significantly-sized
SIZING_SELECTION_WIDGET_WIDTH, // widgets we need to hardcode the combined widget's
SIZING_SELECTION_WIDGET_HEIGHT);
// size, otherwise it will open too small
ICheckStateListener listener = event -> getOkButton().setEnabled(selectionGroup.getCheckedElementCount() > 0);
WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
selectionGroup.setTreeComparator(comparator);
selectionGroup.setListComparator(comparator);
selectionGroup.addCheckStateListener(listener);
addSelectionButtons(composite);
return composite;
}
use of org.eclipse.jface.viewers.ICheckStateListener in project knime-core by knime.
the class WorkflowExportPage method createTreeViewer.
private void createTreeViewer(final Composite parent) {
m_treeViewer = new CheckboxTreeViewer(parent);
m_treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
m_treeViewer.setContentProvider(new ITreeContentProvider() {
// assume to have IContainers as input
@Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IContainer) {
IContainer container = (IContainer) parentElement;
try {
// return only workflows and workflow groups
Collection<IContainer> children = new ArrayList<IContainer>();
for (IResource r : container.members(false)) {
if (KnimeResourceUtil.isWorkflow(r) || KnimeResourceUtil.isWorkflowGroup(r)) {
// if it is a workflow or workflow group
// it must be a container
children.add((IContainer) r);
}
}
return children.toArray();
} catch (CoreException e) {
return new Object[0];
}
}
return new Object[0];
}
@Override
public Object getParent(final Object element) {
if (element instanceof IResource) {
return ((IResource) element).getParent();
}
return null;
}
@Override
public boolean hasChildren(final Object element) {
if (element instanceof IWorkspaceRoot) {
return true;
}
if ((element instanceof IContainer) && KnimeResourceUtil.isWorkflowGroup((IContainer) element)) {
return true;
}
return false;
}
@Override
public Object[] getElements(final Object inputElement) {
return getChildren(inputElement);
}
@Override
public void dispose() {
// nothing to do
}
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// nothing to do
}
});
m_treeViewer.setLabelProvider(new KnimeResourceLabelProvider());
m_treeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
Object o = event.getElement();
boolean isChecked = event.getChecked();
// first expand in order to be able to check children as well
m_treeViewer.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
m_treeViewer.setSubtreeChecked(o, isChecked);
if (o instanceof IResource) {
IResource element = (IResource) o;
setParentTreeChecked(m_treeViewer, element, isChecked);
}
dialogChanged();
getWizard().getContainer().updateButtons();
}
});
m_treeViewer.getTree().setVisible(false);
}
use of org.eclipse.jface.viewers.ICheckStateListener in project knime-core by knime.
the class WorkflowImportSelectionPage method createWorkflowListComposite.
/**
* @param parent parent composite
* @return the lower part of the workflow selection page, the list with
* selected workflows to import
*/
protected Composite createWorkflowListComposite(final Composite parent) {
Group overall = new Group(parent, SWT.FILL);
overall.setText("Workflows:");
overall.setLayoutData(FILL_BOTH);
overall.setLayout(new GridLayout(2, false));
// list with checkboxes....
m_workflowListUI = new CheckboxTreeViewer(overall);
m_workflowListUI.getTree().setLayoutData(FILL_BOTH);
m_workflowListUI.setContentProvider(new ITreeContentProvider() {
@Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IWorkflowImportElement) {
return ((IWorkflowImportElement) parentElement).getChildren().toArray();
}
return new Object[0];
}
@Override
public Object getParent(final Object element) {
if (element instanceof IWorkflowImportElement) {
return ((IWorkflowImportElement) element).getParent();
}
return null;
}
@Override
public boolean hasChildren(final Object element) {
if (element instanceof IWorkflowImportElement) {
return ((IWorkflowImportElement) element).getChildren().size() > 0;
}
return false;
}
@Override
public Object[] getElements(final Object inputElement) {
return getChildren(inputElement);
}
@Override
public void dispose() {
}
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// should never happen
}
});
m_workflowListUI.setLabelProvider(new LabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof IWorkflowImportElement) {
IWorkflowImportElement wf = (IWorkflowImportElement) element;
return wf.getName();
}
return element.toString();
}
@Override
public Image getImage(final Object element) {
if (element instanceof IWorkflowImportElement) {
IWorkflowImportElement wf = (IWorkflowImportElement) element;
// display invalid ones differently
if (wf.isInvalid()) {
return IMG_WARN;
} else if (wf.isWorkflow()) {
return KnimeResourceLabelProvider.CLOSED_WORKFLOW;
} else if (wf.isWorkflowGroup()) {
return KnimeResourceLabelProvider.WORKFLOW_GROUP;
}
}
return super.getImage(element);
}
});
m_workflowListUI.setInput(m_importRoot);
m_workflowListUI.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
Object o = event.getElement();
boolean isChecked = event.getChecked();
// first expand in order to be able to check children as well
m_workflowListUI.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
m_workflowListUI.setSubtreeChecked(o, isChecked);
if (o instanceof IWorkflowImportElement) {
IWorkflowImportElement element = (IWorkflowImportElement) o;
setParentTreeChecked(m_workflowListUI, element, isChecked);
}
validateWorkflows();
}
});
// and 3 buttons -> panel in second column
GridData rightAlign = new GridData();
rightAlign.horizontalAlignment = SWT.RIGHT;
rightAlign.verticalAlignment = SWT.BEGINNING;
Composite buttonPanel = new Composite(overall, SWT.NONE);
buttonPanel.setLayout(new GridLayout(1, false));
buttonPanel.setLayoutData(rightAlign);
// select all
Button selectAllBtn = new Button(buttonPanel, SWT.PUSH);
selectAllBtn.setText("Select All");
selectAllBtn.setLayoutData(m_btnData);
selectAllBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (m_importRoot != null) {
m_workflowListUI.expandAll();
m_workflowListUI.setAllChecked(true);
validateWorkflows();
}
}
});
// deselect all
Button deselectAllBtn = new Button(buttonPanel, SWT.PUSH);
deselectAllBtn.setText("Deselect All");
deselectAllBtn.setLayoutData(m_btnData);
deselectAllBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (m_importRoot != null) {
m_workflowListUI.expandAll();
m_workflowListUI.setAllChecked(false);
validateWorkflows();
}
}
});
// below a check box -> copy projects
m_copyProjectsUI = new Button(overall, SWT.CHECK);
m_copyProjectsUI.setText("Copy projects into workspace");
m_copyProjectsUI.setSelection(true);
m_copyProjectsUI.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(final SelectionEvent e) {
validateWorkflows();
}
});
// if from zip this checkbox must be disabled
m_copyProjectsUI.setEnabled(initialFromDir);
return parent;
}
Aggregations