use of org.eclipse.swt.events.KeyAdapter in project cubrid-manager by CUBRID.
the class QueryRecordListComparator method addTextViewerListener.
/**
* Add SQL viewer listener
*
* @param text
*/
private void addTextViewerListener(final StyledText text) {
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
ServerInfo serverInfo = getServerInfo();
boolean isLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
boolean isNoAutoUpperCase = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
if (!isLowerCase && !isNoAutoUpperCase) {
autoReplaceKeyword();
}
}
// replace keyword to upper case automatically
public void autoReplaceKeyword() {
// FIXME extract tokenize code to utility
if (pendingCompletionsListener) {
return;
}
int pos = text.getCaretOffset() - 1;
if (pos <= 0) {
return;
}
String currentKey = text.getText(pos, pos);
if (currentKey == null || currentKey.length() <= 0) {
return;
}
char cur = currentKey.charAt(0);
if (cur != ' ' && cur != '(' && cur != '\t' && cur != '\n' && cur != '\r' && cur != ',') {
return;
}
pos--;
if (pos < 0) {
return;
}
int spos = pos - 20;
if (spos < 0) {
spos = 0;
}
String txt = text.getText(spos, pos);
spos = pos + 1;
for (int i = txt.length() - 1; i >= 0; i--) {
char c = txt.charAt(i);
if (c == ' ' || c == '\t' || c == '\n' || c == '(') {
break;
}
spos--;
}
int epos = pos;
if (spos < 0 || epos < 0 || spos > epos) {
return;
}
String currentKeyword = text.getText(spos, epos);
if (currentKeyword == null) {
return;
}
int len = currentKeyword.length();
for (int i = 0; i < QuerySyntax.KEYWORDS_AUTO_UPPER.length; i++) {
String keyword = QuerySyntax.KEYWORDS_AUTO_UPPER[i];
if (keyword.equalsIgnoreCase(currentKeyword)) {
pendingCompletionsListener = true;
text.replaceTextRange(spos, len, keyword.toUpperCase());
pendingCompletionsListener = false;
break;
}
}
}
});
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
if ((event.stateMask & SWT.COMMAND) != 0) {
//for Mac
if ((event.stateMask & SWT.SHIFT) != 0) {
if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
runQuery();
return;
}
}
}
if (event.keyCode == SWT.F5 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'e') {
runQuery();
} else if (event.keyCode == SWT.F6 || (event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'l') {
runQueryPlan();
} else if (event.keyCode == SWT.F3) {
if ((event.stateMask & SWT.SHIFT) == 0) {
TextEditorFindReplaceMediator.findNext();
} else {
TextEditorFindReplaceMediator.findPrevious();
}
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == ' ') {
contentAssistant.showPossibleCompletions();
} else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'r') {
recentlyUsedSQLcontentAssistant.showPossibleCompletions();
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) == 0) {
if (event.keyCode == 'z' || event.keyCode == 'Z') {
undoManager.undo();
} else if (event.keyCode == 'y' || event.keyCode == 'Y') {
undoManager.redo();
}
} else if ((event.stateMask & SWT.CTRL) != 0 && (event.stateMask & SWT.SHIFT) != 0) {
if (event.keyCode == 'f' || event.keyCode == 'F') {
try {
formatHandler.execute(null);
} catch (Exception ex) {
CommonUITool.openErrorBox(ex.getMessage());
}
}
} else if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == '/') {
try {
contentAssistHandler.execute(null);
} catch (Exception ex) {
CommonUITool.openErrorBox(ex.getMessage());
}
}
if (SQLContentAssistProcessor.isShowProposal(event.character)) {
contentAssistant.showPossibleCompletions();
useCompletions = true;
} else if ((event.character >= 'A' && event.character <= 'Z') || (event.character >= 'a' && event.character <= 'z')) {
if (useCompletions) {
contentAssistant.showPossibleCompletions();
}
useCompletions = false;
} else if (event.character == ' ' || event.character == '\t' || event.keyCode == SWT.KEYPAD_CR || event.keyCode == SWT.CR || event.keyCode == SWT.BS || (text.getText().trim().length() < 1)) {
useCompletions = true;
}
}
});
TextEditorFindReplaceMediator editorDialogMediator = new TextEditorFindReplaceMediator();
text.addFocusListener(editorDialogMediator);
}
use of org.eclipse.swt.events.KeyAdapter in project dbeaver by serge-rider.
the class ColumnsMappingDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
DBPDataSource targetDataSource = settings.getTargetDataSource(mapping);
getShell().setText("Map columns of " + mapping.getTargetName());
boldFont = UIUtils.makeBoldFont(parent.getFont());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
new Label(composite, SWT.NONE).setText("Source entity: " + DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI) + " [" + mapping.getSource().getDataSource().getContainer().getName() + "]");
new Label(composite, SWT.NONE).setText("Target entity: " + mapping.getTargetName() + " [" + (targetDataSource == null ? "?" : targetDataSource.getContainer().getName()) + "]");
mappingViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 300;
mappingViewer.getTable().setLayoutData(gd);
mappingViewer.getTable().setLinesVisible(true);
mappingViewer.getTable().setHeaderVisible(true);
mappingViewer.setContentProvider(new ListContentProvider());
mappingViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
for (TableItem item : mappingViewer.getTable().getSelection()) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.skip);
}
updateStatus(Status.OK_STATUS);
mappingViewer.refresh();
} else if (e.character == SWT.SPACE) {
for (TableItem item : mappingViewer.getTable().getSelection()) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.existing);
try {
attribute.updateMappingType(VoidProgressMonitor.INSTANCE);
} catch (DBException e1) {
updateStatus(GeneralUtils.makeExceptionStatus(e1));
}
}
mappingViewer.refresh();
}
}
});
{
TableViewerColumn columnSource = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnSource.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
cell.setText(DBUtils.getObjectFullName(attrMapping.getSource(), DBPEvaluationContext.UI));
if (attrMapping.getIcon() != null) {
cell.setImage(DBeaverIcons.getImage(attrMapping.getIcon()));
}
}
});
columnSource.getColumn().setText("Source Column");
columnSource.getColumn().setWidth(170);
}
{
TableViewerColumn columnSourceType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnSourceType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((DatabaseMappingAttribute) cell.getElement()).getSourceType());
}
});
columnSourceType.getColumn().setText("Source Type");
columnSourceType.getColumn().setWidth(100);
}
{
TableViewerColumn columnTarget = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnTarget.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
cell.setText(mapping.getTargetName());
if (mapping.mappingType == DatabaseMappingType.unspecified) {
cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
} else {
cell.setBackground(null);
}
cell.setFont(boldFont);
}
});
columnTarget.getColumn().setText("Target Column");
columnTarget.getColumn().setWidth(170);
columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
try {
java.util.List<String> items = new ArrayList<>();
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) element;
if (mapping.getParent().getMappingType() == DatabaseMappingType.existing && mapping.getParent().getTarget() instanceof DBSEntity) {
DBSEntity parentEntity = (DBSEntity) mapping.getParent().getTarget();
for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(VoidProgressMonitor.INSTANCE))) {
items.add(attr.getName());
}
}
items.add(DatabaseMappingAttribute.TARGET_NAME_SKIP);
CustomComboBoxCellEditor editor = new CustomComboBoxCellEditor(mappingViewer.getTable(), items.toArray(new String[items.size()]), SWT.DROP_DOWN);
updateStatus(Status.OK_STATUS);
return editor;
} catch (DBException e) {
updateStatus(GeneralUtils.makeExceptionStatus(e));
return null;
}
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
return ((DatabaseMappingAttribute) element).getTargetName();
}
@Override
protected void setValue(Object element, Object value) {
try {
String name = CommonUtils.toString(value);
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
if (DatabaseMappingAttribute.TARGET_NAME_SKIP.equals(name)) {
attrMapping.setMappingType(DatabaseMappingType.skip);
} else {
if (attrMapping.getParent().getMappingType() == DatabaseMappingType.existing && attrMapping.getParent().getTarget() instanceof DBSEntity) {
DBSEntity parentEntity = (DBSEntity) attrMapping.getParent().getTarget();
for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(VoidProgressMonitor.INSTANCE))) {
if (name.equalsIgnoreCase(attr.getName())) {
attrMapping.setTarget(attr);
attrMapping.setMappingType(DatabaseMappingType.existing);
return;
}
}
}
attrMapping.setMappingType(DatabaseMappingType.create);
attrMapping.setTargetName(name);
}
updateStatus(Status.OK_STATUS);
} catch (DBException e) {
updateStatus(GeneralUtils.makeExceptionStatus(e));
} finally {
mappingViewer.refresh();
}
}
});
}
{
TableViewerColumn columnTargetType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnTargetType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
cell.setText(attrMapping.getTargetType(dataSource));
cell.setFont(boldFont);
}
});
columnTargetType.getColumn().setText("Target Type");
columnTargetType.getColumn().setWidth(100);
columnTargetType.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
Set<String> types = new LinkedHashSet<>();
DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
if (dataSource instanceof DBPDataTypeProvider) {
for (DBSDataType type : ((DBPDataTypeProvider) dataSource).getLocalDataTypes()) {
types.add(type.getName());
}
}
types.add(attrMapping.getTargetType(dataSource));
return new CustomComboBoxCellEditor(mappingViewer.getTable(), types.toArray(new String[types.size()]), SWT.BORDER);
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
return attrMapping.getTargetType(settings.getTargetDataSource(attrMapping));
}
@Override
protected void setValue(Object element, Object value) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
attrMapping.setTargetType(CommonUtils.toString(value));
mappingViewer.refresh(element);
}
});
}
{
TableViewerColumn columnType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
String text = "";
switch(mapping.getMappingType()) {
case unspecified:
text = "?";
break;
case existing:
text = "existing";
break;
case create:
text = "new";
break;
case skip:
text = "skip";
break;
}
cell.setText(text);
}
});
columnType.getColumn().setText("Mapping");
columnType.getColumn().setWidth(60);
}
mappingViewer.setInput(attributeMappings);
return parent;
}
use of org.eclipse.swt.events.KeyAdapter in project sling by apache.
the class ArchetypeParametersWizardPage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 2;
layout.verticalSpacing = 9;
Label label = new Label(container, SWT.NULL);
label.setText("&Group Id:");
groupId = new Text(container, SWT.BORDER | SWT.SINGLE);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
groupId.setLayoutData(gd);
groupId.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
if (!javaPackageModified) {
if (artifactId.getText().length() == 0) {
javaPackage.setText(getDefaultJavaPackage(groupId.getText(), ""));
} else {
javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
}
}
}
});
label = new Label(container, SWT.NULL);
label.setText("&Artifact Id:");
artifactId = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
artifactId.setLayoutData(gd);
artifactId.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
if (javaPackageModified) {
return;
}
if (groupId.getText().length() == 0) {
javaPackage.setText(getDefaultJavaPackage("", artifactId.getText()));
} else {
javaPackage.setText(getDefaultJavaPackage(groupId.getText(), artifactId.getText()));
}
}
});
label = new Label(container, SWT.NULL);
label.setText("&Version:");
version = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
version.setLayoutData(gd);
version.setText("0.0.1-SNAPSHOT");
version.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
label = new Label(container, SWT.NULL);
label.setText("&Package:");
javaPackage = new Text(container, SWT.BORDER | SWT.SINGLE);
gd = new GridData(GridData.FILL_HORIZONTAL);
javaPackage.setLayoutData(gd);
javaPackageModified = false;
javaPackage.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
javaPackageModified = true;
}
});
javaPackage.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
label = new Label(container, SWT.NULL);
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
label.setLayoutData(gd);
label.setText("&Parameters:");
propertiesViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
propertiesTable = propertiesViewer.getTable();
propertiesTable.setLinesVisible(true);
propertiesTable.setHeaderVisible(true);
propertiesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2));
CellNavigationStrategy strategy = new CellNavigationStrategy();
TableViewerFocusCellManager focusCellMgr = new TableViewerFocusCellManager(propertiesViewer, new FocusCellOwnerDrawHighlighter(propertiesViewer), strategy);
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(propertiesViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
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(propertiesViewer, focusCellMgr, actSupport, features);
TableColumn propertiesTableNameColumn = new TableColumn(propertiesTable, SWT.NONE);
propertiesTableNameColumn.setWidth(130);
propertiesTableNameColumn.setText("Name");
TableColumn propertiesTableValueColumn = new TableColumn(propertiesTable, SWT.NONE);
propertiesTableValueColumn.setWidth(230);
propertiesTableValueColumn.setText("Value");
propertiesViewer.setColumnProperties(new String[] { KEY_PROPERTY, VALUE_PROPERTY });
propertiesViewer.setCellEditors(new CellEditor[] { new TextCellEditor(propertiesTable, SWT.NONE), new TextCellEditor(propertiesTable, SWT.NONE) });
propertiesViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
return true;
}
public void modify(Object element, String property, Object value) {
if (element instanceof TableItem) {
((TableItem) element).setText(getTextIndex(property), String.valueOf(value));
dialogChanged();
}
}
public Object getValue(Object element, String property) {
if (element instanceof TableItem) {
return ((TableItem) element).getText(getTextIndex(property));
}
return null;
}
});
initialize();
setPageComplete(false);
setControl(container);
}
use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.
the class TestSuiteLabelProvider method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText(Messages.TestSuitesPart_section_junit_tests);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// Section toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
addItem.setToolTipText(Messages.TestSuitesPart_add);
final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
removeItem.setToolTipText(Messages.TestSuitesPart_remove);
removeItem.setEnabled(false);
Table table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new TestSuiteLabelProvider());
toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
btnMoveUp.setText("Up");
btnMoveUp.setImage(imgUp);
btnMoveUp.setEnabled(false);
final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
btnMoveDown.setText("Down");
btnMoveDown.setImage(imgDown);
btnMoveDown.setEnabled(false);
// LISTENERS
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
boolean enabled = selection != null && !selection.isEmpty();
removeItem.setEnabled(enabled);
btnMoveUp.setEnabled(enabled);
btnMoveDown.setEnabled(enabled);
getManagedForm().fireSelectionChanged(TestSuitesPart.this, selection);
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (name != null)
doOpenSource(name);
}
});
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new TestSuiteListDropAdapter());
addItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAdd();
}
});
removeItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doRemove();
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
btnMoveUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveUp();
}
});
btnMoveDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveDown();
}
});
// Layout
GridLayout layout;
layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
// gd.widthHint = 75;
gd.heightHint = 75;
table.setLayoutData(gd);
toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
use of org.eclipse.swt.events.KeyAdapter in project bndtools by bndtools.
the class MapValuesContentProvider method createAvailableBundlesPanel.
Control createAvailableBundlesPanel(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
new Label(panel, SWT.NONE).setText("Available Bundles:");
selectionSearchTxt = new Text(panel, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
selectionSearchTxt.setMessage("filter bundle name");
final Tree availableTree = new Tree(panel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
availableViewer = new TreeViewer(availableTree);
availableViewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
availableViewer.setContentProvider(new RepositoryTreeContentProvider());
availableViewer.setAutoExpandLevel(2);
availableViewer.setFilters(new ViewerFilter[] { alreadySelectedFilter });
// Load data
try {
refreshBundleList();
} catch (Exception e) {
setErrorMessage("Error querying repositories: " + e.getMessage());
logger.logError("Error querying repository configuration.", e);
}
// Listeners
selectionSearchTxt.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN)
availableTree.setFocus();
}
});
selectionSearchTxt.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
availableViewer.setFilters(new ViewerFilter[] { alreadySelectedFilter });
}
});
availableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
// Enable add button when a bundle or bundle version is selected on
// the left
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) availableViewer.getSelection();
for (Iterator<?> iter = sel.iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle) {
addButton.setEnabled(true);
return;
}
}
addButton.setEnabled(false);
}
});
availableViewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
doAdd();
}
});
GridLayout layout;
GridData gd;
layout = new GridLayout(1, false);
panel.setLayout(layout);
gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
selectionSearchTxt.setLayoutData(gd);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 300;
gd.widthHint = 250;
availableTree.setLayoutData(gd);
return panel;
}
Aggregations