use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method createFkIndexTabItem.
/**
* Create foreign key/Index tab item.
*
* @param tabFolder the object of TabFolder
*/
private void createFkIndexTabItem(final TabFolder tabFolder) {
final TabItem foreignKeyTabItem = new TabItem(tabFolder, SWT.NONE);
foreignKeyTabItem.setText(Messages.infoIndexesTab);
final Composite composite = new Composite(tabFolder, SWT.NONE);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
foreignKeyTabItem.setControl(composite);
// create the fk table viewer
final Label fkLabel = new Label(composite, SWT.NONE);
fkLabel.setText(Messages.lblFK);
fkTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
fkTable = fkTableView.getTable();
final GridData gdFkTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
fkTable.setLayoutData(gdFkTable);
fkTable.setLinesVisible(true);
fkTable.setHeaderVisible(true);
TableColumn tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnFK);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(119);
tblCol.setText(Messages.tblColumnColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(93);
tblCol.setText(Messages.tblColumnForeignTable);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(143);
tblCol.setText(Messages.tblColumnForeignColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(84);
tblCol.setText(Messages.tblColumnUpdateRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(86);
tblCol.setText(Messages.tblColumnDeleteRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnCacheColumn);
FKTableViewerContentProvider fkContentProvider = new FKTableViewerContentProvider();
FKTableViewerLabelProvider fkLabelProvider = new FKTableViewerLabelProvider(database.getDatabaseInfo(), erSchema);
fkTableView.setContentProvider(fkContentProvider);
fkTableView.setLabelProvider(fkLabelProvider);
fkTableView.setInput(getNewSchemaInfo());
final Composite fkBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
fkBtnComposite.setLayoutData(gdBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
fkBtnComposite.setLayout(gridLayout);
final GridData gdFKBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addFKBTN = new Button(fkBtnComposite, SWT.NONE);
addFKBTN.setLayoutData(gdFKBTN);
addFKBTN.setText(Messages.btnAddFk);
addFKBTN.addSelectionListener(new AddFkBtnListenerOnFkIndexTab());
final Button editFKBTN = new Button(fkBtnComposite, SWT.NONE);
editFKBTN.setLayoutData(gdFKBTN);
editFKBTN.setEnabled(false);
editFKBTN.setText(Messages.btnEditFk);
editFKBTN.addSelectionListener(new EditFkBtnListenerOnFkIndexTab());
final Button deleteFKBTN = new Button(fkBtnComposite, SWT.NONE);
deleteFKBTN.setLayoutData(gdFKBTN);
deleteFKBTN.setEnabled(false);
deleteFKBTN.setText(Messages.btnDelFk);
deleteFKBTN.addSelectionListener(new DelFkBtnListenerOnFkIndexTab());
fkTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (database == null || database.getDatabaseInfo() == null || newSchemaInfo == null) {
return;
}
TableItem[] items = fkTable.getSelection();
if (items == null || items.length == 0) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
} else {
deleteFKBTN.setEnabled(true);
editFKBTN.setEnabled(items.length == 1);
for (TableItem item : items) {
String fkName = item.getText(0);
List<SchemaInfo> superList = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo.getSuperClasses());
if (newSchemaInfo.isInSuperClasses(superList, fkName)) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
}
}
}
}
});
// create index table view
final Label indexLabel = new Label(composite, SWT.NONE);
indexLabel.setText(Messages.lblIndexes);
indexTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
indexTable = indexTableView.getTable();
indexTable.setLinesVisible(true);
indexTable.setHeaderVisible(true);
final GridData gdIndexTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
indexTable.setLayoutData(gdIndexTable);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(150);
tblCol.setText(Messages.tblColumnIndexName);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(78);
tblCol.setText(Messages.tblColumnIndexType);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(218);
tblCol.setText(Messages.tblColumnOnColumns);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(282);
tblCol.setText(Messages.tblColumnIndexRule);
IndexTableViewerContentProvider indexContentProvider = new IndexTableViewerContentProvider();
IndexTableViewerLabelProvider indexLabelProvider = new IndexTableViewerLabelProvider();
indexTableView.setContentProvider(indexContentProvider);
indexTableView.setLabelProvider(indexLabelProvider);
indexTableView.setInput(getNewSchemaInfo());
indexTableView.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
StructuredSelection selected = (StructuredSelection) event.getSelection();
if (selected == null) {
return;
}
Constraint constraint = (Constraint) selected.getFirstElement();
openEditIndexDialog(constraint);
}
});
final Composite indexBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdIndexBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
indexBtnComposite.setLayoutData(gdIndexBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
indexBtnComposite.setLayout(gridLayout);
final GridData gdIndexBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addIndexBTN = new Button(indexBtnComposite, SWT.NONE);
addIndexBTN.setLayoutData(gdIndexBTN);
addIndexBTN.setText(Messages.btnAddIndex);
addIndexBTN.addSelectionListener(new AddIndexBtnListenerOnFkIndexTab());
final Button editIndexBTN = new Button(indexBtnComposite, SWT.NONE);
editIndexBTN.setLayoutData(gdIndexBTN);
editIndexBTN.setEnabled(false);
editIndexBTN.setText(Messages.btnEditIndex);
editIndexBTN.addSelectionListener(new EditIndexBtnListenerOnFkIndexTab());
final Button deleteIndexBTN = new Button(indexBtnComposite, SWT.NONE);
deleteIndexBTN.setLayoutData(gdIndexBTN);
deleteIndexBTN.setEnabled(false);
deleteIndexBTN.setText(Messages.btnDelIndex);
deleteIndexBTN.addSelectionListener(new DelIndexBtnListenerOnFkIndexTab());
indexTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
TableItem[] items = indexTable.getSelection();
if (items == null || items.length == 0) {
deleteIndexBTN.setEnabled(false);
editIndexBTN.setEnabled(false);
} else {
deleteIndexBTN.setEnabled(true);
editIndexBTN.setEnabled(items.length == 1);
}
}
});
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method changeForEditElement.
/**
* Make a change log for editing attribute
*
* @param attrName
* @param editingCol ERD column to be changed by the user
* @param oldCol ERD column
* @return
*/
public boolean changeForEditElement(String attrName, ERTableColumn editingCol, ERTableColumn oldCol) {
// FIXME move this logic to core module
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (database == null || editingCol == null) {
return false;
}
editingCol.getAttr().setInherit(newSchemaInfo.getClassname());
String newAttrName = editingCol.getAttr().getName();
if (oldCol == null) {
oldCol = new ERTableColumn(newERTable, editingCol.getAttr(), false);
oldCol.setIsNew(true);
}
DBAttribute oldAttr = oldCol.getAttr();
DBAttribute editingAttr = editingCol.getAttr();
if (!oldAttr.isUnique() && newSchemaInfo.getUniqueByAttrName(editingAttr.getName()) == null && editingAttr.isUnique()) {
Constraint unique = new Constraint(true);
unique.setType(Constraint.ConstraintType.UNIQUE.getText());
unique.addAttribute(newAttrName);
unique.addRule(newAttrName + " ASC");
unique.setName(ConstraintNamingUtil.getUniqueName(newSchemaInfo.getClassname(), unique.getRules()));
newSchemaInfo.addConstraint(unique);
} else if (oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
} else if (!oldAttr.isUnique() && !editingAttr.isUnique()) {
newSchemaInfo.removeUniqueByAttrName(attrName);
}
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
if (database != null && database.getDatabaseInfo() != null && newSchemaInfo != null) {
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(editingCol), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
return true;
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method addNewColumn.
public void addNewColumn() {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (newSchemaInfo == null) {
return;
}
// boolean hasNotFinishedColumn = false;
boolean hasDuplicatedColumn = false;
List<ERTableColumn> items = newERTable.getColumns();
if (items != null && items.size() > 0) {
Set<String> matches = new HashSet<String>();
// check whether there is no name column
for (ERTableColumn col : items) {
if (col == null) {
continue;
}
if (StringUtil.isEmpty(col.getName(erSchema.isPhysicModel()))) {
continue;
}
if (matches.contains(col.getName(erSchema.isPhysicModel()))) {
hasDuplicatedColumn = true;
break;
}
matches.add(col.getName(erSchema.isPhysicModel()));
}
}
if (hasDuplicatedColumn) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
return;
}
String collation = null;
if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
collation = newSchemaInfo.getCollation();
} else {
collation = Collation.DEFAULT_COLLATION;
}
DBAttribute addAttribute = new DBAttribute("", DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
ERTableColumn column = new ERTableColumn(newERTable, addAttribute, false);
column.setIsNew(true);
tempERColumnList.add(column);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(addAttribute), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class TableViewerEditor method updateFocusCell.
/**
* Update the focus cell
*
* @param focusCell ViewerCell
* @param event ColumnViewerEditorActivationEvent
*/
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
// events
if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
IStructuredSelection selecion = (IStructuredSelection) getViewer().getSelection();
@SuppressWarnings("rawtypes") List list = selecion == null ? new ArrayList() : selecion.toList();
if (!list.contains(focusCell.getElement())) {
getViewer().setSelection(new StructuredSelection(focusCell.getElement()), true);
}
// the cell is not scrolled into view
if (focusCellManager != null) {
focusCellManager.setFocusCell(focusCell);
}
}
}
use of org.eclipse.jface.viewers.StructuredSelection in project azure-tools-for-java by Microsoft.
the class AzureNewDockerConfigPage method updateDockerSubscriptionComboBox.
private void updateDockerSubscriptionComboBox(Composite mainContainer) {
dockerSubscriptionComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection.size() > 0) {
AzureDockerSubscription currentSubscription = (AzureDockerSubscription) selection.getFirstElement();
dockerSubscriptionIdTextField.setText(currentSubscription != null ? currentSubscription.id : "");
wizard.setSubscription(currentSubscription);
errDispatcher.removeMessage("dockerSubscriptionCombo", dockerSubscriptionCombo);
updateDockerLocationComboBox(mainContainer, currentSubscription);
updateDockerHostSelectRGComboBox(mainContainer, currentSubscription);
String region = (String) dockerLocationComboBox.getText();
Region regionObj = Region.findByLabelOrName(region);
updateDockerSelectVnetComboBox(mainContainer, currentSubscription, regionObj != null ? regionObj.name() : region);
updateDockerSelectStorageComboBox(mainContainer, currentSubscription);
setPageComplete(doValidate());
} else {
errDispatcher.addMessage("dockerSubscriptionCombo", "No active subscriptions found", null, IMessageProvider.ERROR, dockerSubscriptionCombo);
setPageComplete(false);
}
}
});
dockerSubscriptionComboViewer.setContentProvider(ArrayContentProvider.getInstance());
dockerSubscriptionComboViewer.setInput(dockerManager.getSubscriptionsList());
if (dockerManager.getSubscriptionsList() != null && dockerManager.getSubscriptionsList().size() > 0) {
dockerSubscriptionCombo.select(0);
dockerSubscriptionIdTextField.setText(((AzureDockerSubscription) ((StructuredSelection) dockerSubscriptionComboViewer.getSelection()).getFirstElement()).id);
wizard.setSubscription((AzureDockerSubscription) ((StructuredSelection) dockerSubscriptionComboViewer.getSelection()).getFirstElement());
}
}
Aggregations