use of org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog in project jbosstools-hibernate by jbosstools.
the class TablePropertiesBlock method createTreeSelectionDialog.
private CheckedTreeSelectionDialog createTreeSelectionDialog() {
return new CheckedTreeSelectionDialog(getComposite().getShell(), new AnyAdaptableLabelProvider(), new DeferredContentProvider()) {
protected Composite createSelectionButtons(Composite composite) {
Composite buttonComposite = new Composite(composite, SWT.RIGHT);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
buttonComposite.setLayout(layout);
buttonComposite.setFont(composite.getFont());
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
data.grabExcessHorizontalSpace = true;
composite.setData(data);
Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, MapperMessages.TablePropertiesBlock_select_all_children, false);
SelectionListener listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection viewerElements = (IStructuredSelection) getTreeViewer().getSelection();
Iterator<?> iterator = viewerElements.iterator();
while (iterator.hasNext()) {
getTreeViewer().setSubtreeChecked(iterator.next(), true);
}
updateOKStatus();
}
};
selectButton.addSelectionListener(listener);
Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, MapperMessages.TablePropertiesBlock_deselect_all, false);
listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getTreeViewer().setCheckedElements(new Object[0]);
updateOKStatus();
}
};
deselectButton.addSelectionListener(listener);
return buttonComposite;
}
protected boolean evaluateIfTreeEmpty(Object input) {
return false;
}
};
}
use of org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog in project jbosstools-hibernate by jbosstools.
the class TablePropertiesBlock method doAdd.
protected void doAdd() {
CheckedTreeSelectionDialog dialog = createTreeSelectionDialog();
LazyDatabaseSchema lds = editor.getLazyDatabaseSchema();
List<ITable> tables = new ArrayList<ITable>();
Map<ITable, List<IColumn>> columns = new HashMap<ITable, List<IColumn>>();
if (lds == null) {
// $NON-NLS-1$ //$NON-NLS-2$
String tableName = "", namePrefix = "TABLE_";
IRevEngTable retable = editor.getReverseEngineeringDefinition().createTable();
// $NON-NLS-1$
retable.setCatalog("");
// $NON-NLS-1$
retable.setSchema("");
TreeSet<String> ts = new TreeSet<String>();
IRevEngTable[] retables = editor.getReverseEngineeringDefinition().getTables();
char separartor = '%';
for (int i = 0; i < retables.length; i++) {
ts.add(retables[i].getCatalog() + separartor + retables[i].getSchema() + separartor + retables[i].getName());
}
String strCatalogSchema = retable.getCatalog() + separartor + retable.getSchema() + separartor;
int i = 0;
do {
tableName = namePrefix + (i++);
} while (ts.contains(strCatalogSchema + tableName));
retable.setName(tableName);
editor.getReverseEngineeringDefinition().addTable(retable);
} else {
dialog.setTitle(MapperMessages.TablePropertiesBlock_add_tables_columns);
dialog.setMessage(MapperMessages.TablePropertiesBlock_select_tables_columns);
dialog.setInput(lds);
dialog.setContainerMode(true);
dialog.open();
Object[] result = dialog.getResult();
ITable lastTable = null;
if (result != null) {
for (int i = 0; i < result.length; i++) {
Object object = result[i];
if (object instanceof ITable) {
ITable table = (ITable) object;
tables.add(table);
lastTable = table;
} else if (object instanceof IColumn) {
IColumn column = (IColumn) object;
List<IColumn> existing = columns.get(lastTable);
if (existing == null) {
existing = new ArrayList<IColumn>();
columns.put(lastTable, existing);
}
existing.add(column);
} else if (object instanceof IPrimaryKey) {
List<IColumn> existing = columns.get(lastTable);
if (existing == null) {
existing = new ArrayList<IColumn>();
columns.put(lastTable, existing);
}
existing.addAll(((IPrimaryKey) object).getColumns());
}
}
}
Iterator<ITable> iterator = tables.iterator();
while (iterator.hasNext()) {
ITable table = iterator.next();
IRevEngTable retable = null;
// editor.getReverseEngineeringDefinition().findTable(TableIdentifier.create(table));
if (retable == null) {
retable = editor.getReverseEngineeringDefinition().createTable();
retable.setCatalog(table.getCatalog());
retable.setSchema(table.getSchema());
retable.setName(table.getName());
editor.getReverseEngineeringDefinition().addTable(retable);
}
List<IColumn> columnList = columns.get(table);
if (columnList != null) {
Iterator<IColumn> colIterator = columnList.iterator();
while (colIterator.hasNext()) {
IColumn column = colIterator.next();
IRevEngColumn revCol = editor.getReverseEngineeringDefinition().createColumn();
revCol.setName(column.getName());
if (column.getSqlType() != null) {
// TODO: should not be required
revCol.setJDBCType(column.getSqlType());
}
retable.addColumn(revCol);
}
}
}
// editor.getReverseEngineeringDefinition();
}
}
Aggregations