use of org.eclipse.jface.viewers.SelectionChangedEvent in project sling by apache.
the class MVPEditor method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
// now add the node type dropbox-combo
Composite header = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
layout.numColumns = 3;
header.setLayout(layout);
Label label = new Label(header, SWT.WRAP);
label.setText("Modify property " + property.getName() + ":");
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
ToolBar buttonBar = new ToolBar(header, SWT.NONE);
ToolItem invisible = new ToolItem(buttonBar, SWT.NONE);
ToolItem plus = new ToolItem(buttonBar, SWT.NONE);
plus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD).createImage());
plus.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
plus();
}
});
final ToolItem minus = new ToolItem(buttonBar, SWT.NONE);
minus.setImage(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE).createImage());
minus.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
minus();
}
});
minus.setEnabled(false);
Composite tableParent = new Composite(composite, SWT.NONE);
final GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.heightHint = 150;
tableParent.setLayoutData(layoutData);
TableColumnLayout tableLayout = new TableColumnLayout();
tableParent.setLayout(tableLayout);
viewer = new TableViewer(tableParent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
// accessing property here directly, instead of going via (JcrProperty)inputElement;
String[] rawLines = property.getValuesAsString();
// convert raw lines to Line objects for easier editing management
for (int i = 0; i < rawLines.length; i++) {
lines.add(new Line(rawLines[i]));
}
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return lines.toArray();
}
});
TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
column0.getColumn().setText("Type");
column0.getColumn().setResizable(true);
column0.getColumn().setWidth(100);
tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(20, 100));
column0.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
try {
cell.setText(property.getTypeAsString());
cell.setForeground(greyColor);
} catch (Exception e) {
cell.setText("n/a");
cell.setForeground(greyColor);
}
}
});
TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
column1.getColumn().setText("Value");
column1.getColumn().setResizable(true);
column1.getColumn().setWidth(200);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(80, 200));
column1.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Line line = (Line) cell.getElement();
cell.setText(line.getValue());
}
});
column1.setEditingSupport(new EditingSupport(viewer) {
@Override
protected void setValue(Object element, Object value) {
Line line = (Line) element;
line.setValue(String.valueOf(value));
// trigger a refresh:
viewer.setInput(property);
}
@Override
protected Object getValue(Object element) {
final Line line = (Line) element;
final String value = line.getValue();
System.out.println("Value=" + value);
return value;
}
@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor(viewer.getTable());
}
@Override
protected boolean canEdit(Object element) {
// all values are editable
return true;
}
});
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()) {
minus.setEnabled(false);
} else {
minus.setEnabled(true);
}
} else {
minus.setEnabled(false);
}
}
});
viewer.setInput(property);
return composite;
}
use of org.eclipse.jface.viewers.SelectionChangedEvent 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.SelectionChangedEvent in project bndtools by bndtools.
the class ImportBndWorkspaceWizardPageOne method createControl.
@Override
public void createControl(final Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
Label lblFolder = new Label(container, SWT.NONE);
lblFolder.setText("Root Directory:");
txtFolder = new Text(container, SWT.BORDER | SWT.SINGLE);
txtFolder.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
getWizard().getContainer().updateButtons();
}
});
//Adding the decorator
txtFolderErrorDecorator = new ControlDecoration(txtFolder, SWT.TOP | SWT.RIGHT);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
Image img = fieldDecoration.getImage();
txtFolderErrorDecorator.setImage(img);
txtFolderErrorDecorator.setDescriptionText("Selected folder must contain valid Bnd Workspace configuration project.");
// hiding it initially
txtFolderErrorDecorator.hide();
Button btnOpenDialog = new Button(container, SWT.PUSH);
btnOpenDialog.setText("Browse...");
btnOpenDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dirDialog = new DirectoryDialog(container.getShell());
dirDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
dirDialog.setText("Select the folder containing the project.");
txtFolder.setText(dirDialog.open());
getWizard().getContainer().updateButtons();
}
});
Label lblProjects = new Label(container, SWT.NONE);
lblProjects.setText("Projects:");
tableViewer = new TableViewer(container, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
// configuration project always first
if (e1 instanceof File && e2 instanceof Project) {
return -1;
} else if (e1 instanceof Project && e2 instanceof File) {
return 1;
}
Project p1 = (Project) e1;
Project p2 = (Project) e2;
return super.compare(viewer, p1.getName(), p2.getName());
}
});
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
// Disable selection since the tableviewer should be readonly, but not disabled
if (!event.getSelection().isEmpty()) {
tableViewer.setSelection(StructuredSelection.EMPTY);
}
}
});
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.setLabelProvider(new ProjectsColumnLabelProvider());
Button refreshButton = new Button(container, SWT.PUSH);
refreshButton.setText("Refresh");
refreshButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
getWizard().getContainer().updateButtons();
}
});
deleteButton = new Button(container, SWT.CHECK);
deleteButton.setText("Delete existing settings");
inferExecutionEnvironmentButton = new Button(container, SWT.CHECK);
inferExecutionEnvironmentButton.setSelection(true);
inferExecutionEnvironmentButton.setText("Infer execution-environment (J2SE and JavaSE).");
inferExecutionEnvironmentButton.setToolTipText("Uses the 'javac.target' from the Bnd Workspace to infer a Execution Environment to the JRE container. If nothing matches, the default JRE will be used.\nExisting containers will be removed.");
FormLayout layout = new FormLayout();
container.setLayout(layout);
FormData fd_lblFolder = new FormData();
fd_lblFolder.top = new FormAttachment(0, 10);
fd_lblFolder.left = new FormAttachment(0, 10);
lblFolder.setLayoutData(fd_lblFolder);
FormData fd_txtFolder = new FormData();
fd_txtFolder.top = new FormAttachment(lblFolder, 0, SWT.CENTER);
fd_txtFolder.left = new FormAttachment(lblFolder, 10);
fd_txtFolder.right = new FormAttachment(100, -100);
txtFolder.setLayoutData(fd_txtFolder);
FormData fd_btnDialog = new FormData();
fd_btnDialog.top = new FormAttachment(lblFolder, 0, SWT.CENTER);
fd_btnDialog.left = new FormAttachment(txtFolder, 10);
fd_btnDialog.right = new FormAttachment(100, -10);
btnOpenDialog.setLayoutData(fd_btnDialog);
FormData fd_lblProjects = new FormData();
fd_lblProjects.top = new FormAttachment(lblFolder, 20);
fd_lblProjects.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
lblProjects.setLayoutData(fd_lblProjects);
FormData fd_table = new FormData();
fd_table.top = new FormAttachment(lblProjects, 5);
fd_table.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
fd_table.right = new FormAttachment(100, -100);
fd_table.bottom = new FormAttachment(100, -55);
tableViewer.getTable().setLayoutData(fd_table);
FormData fd_btnRefresh = new FormData();
fd_btnRefresh.top = new FormAttachment(tableViewer.getTable(), 0, SWT.TOP);
fd_btnRefresh.left = new FormAttachment(btnOpenDialog, 0, SWT.LEFT);
fd_btnRefresh.right = new FormAttachment(100, -10);
refreshButton.setLayoutData(fd_btnRefresh);
FormData fd_btnDelete = new FormData();
fd_btnDelete.top = new FormAttachment(tableViewer.getTable(), 10);
fd_btnDelete.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
deleteButton.setLayoutData(fd_btnDelete);
FormData fd_btnInfer = new FormData();
fd_btnInfer.top = new FormAttachment(deleteButton, 10);
fd_btnInfer.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
inferExecutionEnvironmentButton.setLayoutData(fd_btnInfer);
getShell().setMinimumSize(470, 450);
// required to avoid an error in the system
setControl(parent);
setPageComplete(false);
txtFolder.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project bndtools by bndtools.
the class RunPropertiesPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText("Runtime Properties");
final Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// Create controls: Run Properties
Label lblRunProperties = toolkit.createLabel(composite, "OSGi Framework properties:");
tblRunProperties = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewRunProperties = new TableViewer(tblRunProperties);
runPropertiesModifier = new MapEntryCellModifier<>(viewRunProperties);
tblRunProperties.setHeaderVisible(true);
final TableColumn tblRunPropsCol1 = new TableColumn(tblRunProperties, SWT.NONE);
tblRunPropsCol1.setText("Name");
tblRunPropsCol1.setWidth(100);
final TableColumn tblRunPropsCol2 = new TableColumn(tblRunProperties, SWT.NONE);
tblRunPropsCol1.setText("Value");
tblRunPropsCol1.setWidth(100);
viewRunProperties.setUseHashlookup(true);
viewRunProperties.setColumnProperties(MapEntryCellModifier.getColumnProperties());
runPropertiesModifier.addCellEditorsToViewer();
viewRunProperties.setCellModifier(runPropertiesModifier);
viewRunProperties.setContentProvider(new MapContentProvider());
viewRunProperties.setLabelProvider(new PropertiesTableLabelProvider());
Control createRemovePropsToolBar = createRemovePropsPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
// Create controls: program args
Label lblProgramArgs = toolkit.createLabel(composite, "Launcher Arguments:");
txtProgramArgs = toolkit.createText(composite, "", SWT.MULTI | SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtProgramArgs, Constants.RUNPROGRAMARGS);
// Create controls: vm args
Label lblVmArgs = toolkit.createLabel(composite, "JVM Arguments:");
txtVmArgs = toolkit.createText(composite, "", SWT.MULTI | SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtVmArgs, Constants.RUNVM);
// Layout
GridLayout gl;
GridData gd;
gl = new GridLayout(2, false);
gl.marginWidth = 0;
gl.marginHeight = 0;
composite.setLayout(gl);
lblRunProperties.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.heightHint = 50;
gd.widthHint = 50;
tblRunProperties.setLayoutData(gd);
gd = new GridData(SWT.FILL, SWT.TOP, false, true);
createRemovePropsToolBar.setLayoutData(gd);
lblProgramArgs.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gd.heightHint = 40;
gd.widthHint = 50;
txtProgramArgs.setLayoutData(gd);
lblVmArgs.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
gd.heightHint = 40;
gd.widthHint = 50;
txtVmArgs.setLayoutData(gd);
// Listeners
viewRunProperties.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
createRemovePropsPart.setRemoveEnabled(!viewRunProperties.getSelection().isEmpty());
}
});
createRemovePropsPart.addListener(new AddRemoveListener() {
@Override
public void addSelected() {
runProperties.put("name", "");
viewRunProperties.add("name");
markDirty();
viewRunProperties.editElement("name", 0);
}
@Override
public void removeSelected() {
@SuppressWarnings("rawtypes") Iterator iter = ((IStructuredSelection) viewRunProperties.getSelection()).iterator();
while (iter.hasNext()) {
Object item = iter.next();
runProperties.remove(item);
viewRunProperties.remove(item);
}
markDirty();
}
});
runPropertiesModifier.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
markDirty();
}
});
txtProgramArgs.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
markDirty();
programArgs = txtProgramArgs.getText();
if (programArgs.length() == 0)
programArgs = null;
}
});
}
});
txtVmArgs.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
markDirty();
vmArgs = txtVmArgs.getText();
if (vmArgs.length() == 0)
vmArgs = null;
}
});
}
});
composite.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle area = composite.getClientArea();
Point preferredSize = tblRunProperties.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = area.width - 2 * tblRunProperties.getBorderWidth();
if (preferredSize.y > area.height + tblRunProperties.getHeaderHeight()) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = tblRunProperties.getVerticalBar().getSize();
width -= vBarSize.x;
}
Point oldSize = tblRunProperties.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
tblRunPropsCol1.setWidth(width / 3);
tblRunPropsCol2.setWidth(width - tblRunPropsCol1.getWidth());
tblRunProperties.setSize(area.width, area.height);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
tblRunProperties.setSize(area.width, area.height);
tblRunPropsCol1.setWidth(width / 3);
tblRunPropsCol2.setWidth(width - tblRunPropsCol1.getWidth());
}
}
});
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project bndtools by bndtools.
the class RepositoryBundleSelectionPart method createSection.
void createSection(Section section, FormToolkit toolkit) {
// Toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(getLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ToolItem remove = getRemoveItemTool();
if (remove != null)
remove.setEnabled(isRemovable(event.getSelection()));
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (FileTransfer.getInstance().isSupportedType(transferType))
return true;
if (ResourceTransfer.getInstance().isSupportedType(transferType))
return true;
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
if (!selectionIsDroppable(iterator.next())) {
return false;
}
}
return true;
}
private boolean selectionIsDroppable(Object element) {
return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
}
@Override
public boolean performDrop(Object data) {
TransferData transfer = getCurrentEvent().currentDataType;
if (URLTransfer.getInstance().isSupportedType(transfer)) {
String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
return handleURLDrop(urlStr);
} else if (data instanceof String[]) {
return handleFileNameDrop((String[]) data);
} else if (data instanceof IResource[]) {
return handleResourceDrop((IResource[]) data);
} else {
return handleSelectionDrop();
}
}
private boolean handleResourceDrop(IResource[] resources) {
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
return handleFileDrop(files);
}
private boolean handleFileNameDrop(String[] paths) {
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
return handleFileDrop(files);
}
private boolean handleFileDrop(File[] files) {
if (files.length > 0) {
BndPreferences prefs = new BndPreferences();
boolean hideWarning = prefs.getHideWarningExternalFile();
if (!hideWarning) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
if (Window.CANCEL == dialog.getReturnCode())
return false;
if (dialog.getToggleState()) {
prefs.setHideWarningExternalFile(true);
}
}
AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
for (Pair<String, String> addingBundle : addingBundles) {
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
}
handleAdd(addingClauses);
}
return true;
}
return false;
}
private boolean handleSelectionDrop() {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
List<VersionedClause> adding = new LinkedList<VersionedClause>();
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
if (item instanceof RepositoryBundle) {
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
adding.add(newClause);
} else if (item instanceof RepositoryBundleVersion) {
RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
adding.add(newClause);
} else if (item instanceof RepositoryResourceElement) {
RepositoryResourceElement elt = (RepositoryResourceElement) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
adding.add(newClause);
}
}
handleAdd(adding);
return true;
}
private boolean handleURLDrop(String urlStr) {
try {
URI uri = new URI(sanitizeUrl(urlStr));
AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (dialog.open() == Window.OK) {
Set<ResourceDescriptor> resources = wizard.getResult();
List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
for (ResourceDescriptor resource : resources) {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
VersionedClause clause = new VersionedClause(resource.bsn, attrs);
newBundles.add(clause);
}
handleAdd(newBundles);
return true;
}
return false;
} catch (URISyntaxException e) {
MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
return false;
}
}
private String sanitizeUrl(String urlStr) {
int newline = urlStr.indexOf('\n');
if (newline > -1)
return urlStr.substring(0, newline).trim();
return urlStr;
}
private void handleAdd(Collection<VersionedClause> newClauses) {
if (newClauses == null || newClauses.isEmpty())
return;
List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
for (VersionedClause newClause : newClauses) {
boolean found = false;
for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
VersionedClause existing = iter.next();
if (newClause.getName().equals(existing.getName())) {
int index = iter.previousIndex();
iter.set(newClause);
viewer.replace(newClause, index);
found = true;
break;
}
}
if (!found)
toAdd.add(newClause);
}
bundles.addAll(toAdd);
viewer.add(toAdd.toArray());
markDirty();
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
// Layout
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 50;
gd.heightHint = getTableHeightHint();
table.setLayoutData(gd);
}
Aggregations