import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
private void initialize2(ILayersEditor layers, IDiagram diagram) {
layers.addLayersListener(layersListener);
- Button addButton = new Button(composite, SWT.NONE);
- addButton.setText(Messages.DiagramLayersPage_New);
- addButton.setToolTipText(Messages.DiagramLayersPage_NewTT);
- addButton.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- String name = findFreshName(layers, Messages.DiagramLayersPage_NewRole);
- SimpleLayer layer = new SimpleLayer(name);
- layers.addLayer(layer);
- layers.activate(layer);
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- });
-
- final Button removeButton = new Button(composite, SWT.NONE);
- removeButton.setText(Messages.DiagramLayersPage_Remove);
- removeButton.setToolTipText(Messages.DiagramLayersPage_RemoveTT);
- removeButton.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- TreeItem[] items = viewer.getTree().getSelection();
- if (items.length == 0)
- return;
-
- TreeItem[] all = viewer.getTree().getItems();
- int firstIndex = Arrays.indexOf(all, items[0]);
- for (TreeItem item : items) {
- int index = Arrays.indexOf(all, item);
- all[index] = null;
- ILayer layer = (ILayer)item.getData();
- layers.removeLayer(layer);
- }
- int selectIndex = firstIndex - 1;
- if (firstIndex == 0) {
- for (int i = firstIndex; i < all.length; ++i)
- if (all[i] != null) {
- selectIndex = i;
- break;
- }
- }
- if (selectIndex >= 0) {
- viewer.getTree().select(all[selectIndex]);
- }
- context.getThreadAccess().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- if(context.isDisposed()) return;
- context.getContentContext().setDirty();
- }
-
- });
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
-
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
+ composite.setLayoutData(gridData);
+ composite.setLayout(new GridLayout(3, false));
+
ignoreVisibilityButton = new Button(composite, SWT.CHECK);
+ ignoreVisibilityButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
ignoreVisibilityButton.setText(TEXT_IGNORE_VISIBILITY_SETTINGS);
ignoreVisibilityButton.setToolTipText(TOOLTIP_IGNORE_VISIBILITY_SETTINGS);
ignoreVisibilityButton.setSelection(layers.getIgnoreVisibilitySettings());
});
ignoreFocusButton = new Button(composite, SWT.CHECK);
+ ignoreFocusButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
ignoreFocusButton.setText(TEXT_IGNORE_FOCUS_SETTINGS);
ignoreFocusButton.setToolTipText(TOOLTIP_IGNORE_FOCUS_SETTINGS);
ignoreFocusButton.setSelection(layers.getIgnoreFocusSettings());
});
+ Button addButton = new Button(composite, SWT.NONE);
+ addButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ addButton.setText(Messages.DiagramLayersPage_New);
+ addButton.setToolTipText(Messages.DiagramLayersPage_NewTT);
+ addButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String name = findFreshName(layers, Messages.DiagramLayersPage_NewRole);
+ SimpleLayer layer = new SimpleLayer(name);
+ layers.addLayer(layer);
+ layers.activate(layer);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ });
+
viewer = new CheckboxTreeViewer(composite, SWT.BORDER | SWT.FULL_SELECTION );
GridDataFactory.fillDefaults().grab(true, true).span(4, 1).applyTo(viewer.getControl());
return;
startEditing(layer, item);
+ } else if (event.keyCode == SWT.DEL) {
+ removeSelectedLayers();
}
}
});
}
});
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection s = event.getSelection();
- if (s.isEmpty()) {
- removeButton.setEnabled(false);
- } else {
- removeButton.setEnabled(true);
- }
- }
- });
-
viewer.setContentProvider(new ITreeContentProvider(){
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
public void setSelection(ISelection selection) {
}
+ private void removeSelectedLayers() {
+ TreeItem[] items = viewer.getTree().getSelection();
+ if (items.length == 0)
+ return;
+
+ TreeItem[] all = viewer.getTree().getItems();
+ int firstIndex = Arrays.indexOf(all, items[0]);
+ for (TreeItem item : items) {
+ int index = Arrays.indexOf(all, item);
+ all[index] = null;
+ ILayer layer = (ILayer)item.getData();
+ layers.removeLayer(layer);
+ }
+ int selectIndex = firstIndex - 1;
+ if (firstIndex == 0) {
+ for (int i = firstIndex; i < all.length; ++i)
+ if (all[i] != null) {
+ selectIndex = i;
+ break;
+ }
+ }
+ if (selectIndex >= 0) {
+ viewer.getTree().select(all[selectIndex]);
+ }
+ context.getThreadAccess().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if(context.isDisposed()) return;
+ context.getContentContext().setDirty();
+ }
+
+ });
+ }
+
private boolean startEditing(final ILayer layer, final TreeItem item/*, final int columnIndex*/) {
// Column column = columns[columnIndex];