Search in sources :

Example 1 with IRevEngColumn

use of org.hibernate.eclipse.console.model.IRevEngColumn in project jbosstools-hibernate by jbosstools.

the class TablePropertiesBlock method doDelete.

protected void doDelete() {
    ISelection sel = viewer.getSelection();
    if (sel.isEmpty() || !(sel instanceof TreeSelection)) {
        return;
    }
    boolean updateSelection = false;
    TreeSelection ts = (TreeSelection) sel;
    List<?> list = ts.toList();
    for (Iterator<?> it = list.iterator(); it.hasNext(); ) {
        Object obj = it.next();
        if (obj instanceof IRevEngTable) {
            IRevEngTable retable = (IRevEngTable) obj;
            if (retable instanceof RevEngTableAdapter) {
                updateSelection = true;
            }
            editor.getReverseEngineeringDefinition().removeTable(retable);
        } else if (obj instanceof IRevEngColumn) {
            IRevEngColumn recolumn = (IRevEngColumn) obj;
            if (recolumn instanceof RevEngColumnAdapter) {
                updateSelection = true;
            }
            editor.getReverseEngineeringDefinition().removeColumn(recolumn);
        } else if (obj instanceof IRevEngPrimaryKey) {
            IRevEngPrimaryKey reprimaryKey = (IRevEngPrimaryKey) obj;
            if (reprimaryKey instanceof RevEngPrimaryKeyAdapter) {
                updateSelection = true;
            }
            editor.getReverseEngineeringDefinition().removePrimaryKey(reprimaryKey);
        } else if (obj instanceof IRevEngGenerator) {
            IRevEngGenerator regenerator = (IRevEngGenerator) obj;
            if (regenerator instanceof RevEngGeneratorAdapter) {
                updateSelection = true;
            }
            editor.getReverseEngineeringDefinition().removeGenerator(regenerator);
        } else if (obj instanceof IRevEngParameter) {
            IRevEngParameter reparam = (IRevEngParameter) obj;
            if (reparam instanceof RevEngParamAdapter) {
                updateSelection = true;
            }
            editor.getReverseEngineeringDefinition().removeParameter(reparam);
        }
    }
    if (updateSelection) {
        // if it possible select first item
        TreeItem[] treeItems = viewer.getTree().getItems();
        if (treeItems.length > 0) {
            viewer.getTree().setSelection(treeItems[0]);
        }
    }
}
Also used : RevEngPrimaryKeyAdapter(org.hibernate.eclipse.mapper.model.RevEngPrimaryKeyAdapter) TreeItem(org.eclipse.swt.widgets.TreeItem) IRevEngGenerator(org.hibernate.eclipse.console.model.IRevEngGenerator) IRevEngColumn(org.hibernate.eclipse.console.model.IRevEngColumn) RevEngParamAdapter(org.hibernate.eclipse.mapper.model.RevEngParamAdapter) IRevEngParameter(org.hibernate.eclipse.console.model.IRevEngParameter) RevEngTableAdapter(org.hibernate.eclipse.mapper.model.RevEngTableAdapter) IRevEngPrimaryKey(org.hibernate.eclipse.console.model.IRevEngPrimaryKey) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IRevEngTable(org.hibernate.eclipse.console.model.IRevEngTable) RevEngColumnAdapter(org.hibernate.eclipse.mapper.model.RevEngColumnAdapter) RevEngGeneratorAdapter(org.hibernate.eclipse.mapper.model.RevEngGeneratorAdapter) ISelection(org.eclipse.jface.viewers.ISelection)

Example 2 with IRevEngColumn

use of org.hibernate.eclipse.console.model.IRevEngColumn in project jbosstools-hibernate by jbosstools.

the class TablePropertiesContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof IRevEngTable) {
        IRevEngTable revEngTable = ((IRevEngTable) parentElement);
        IRevEngPrimaryKey primaryKey = revEngTable.getPrimaryKey();
        IRevEngColumn[] columns = revEngTable.getColumns();
        if (primaryKey != null) {
            Object[] des = new Object[columns.length + 1];
            des[0] = primaryKey;
            System.arraycopy(columns, 0, des, 1, columns.length);
            return des;
        } else {
            return columns;
        }
    } else if (parentElement instanceof IRevEngColumn) {
        return new Object[0];
    } else if (parentElement instanceof IRevEngPrimaryKey) {
        IRevEngPrimaryKey pk = (IRevEngPrimaryKey) parentElement;
        IRevEngGenerator generator = pk.getGenerator();
        IRevEngColumn[] columns = pk.getColumns();
        if (generator != null) {
            Object[] des = new Object[columns.length + 1];
            des[0] = generator;
            System.arraycopy(columns, 0, des, 1, columns.length);
            return des;
        } else {
            return columns;
        }
    } else if (parentElement instanceof IRevEngGenerator) {
        IRevEngGenerator generator = (IRevEngGenerator) parentElement;
        return generator.getParameters();
    } else {
        return new Object[0];
    }
}
Also used : IRevEngPrimaryKey(org.hibernate.eclipse.console.model.IRevEngPrimaryKey) IRevEngTable(org.hibernate.eclipse.console.model.IRevEngTable) IRevEngGenerator(org.hibernate.eclipse.console.model.IRevEngGenerator) IRevEngColumn(org.hibernate.eclipse.console.model.IRevEngColumn)

Example 3 with IRevEngColumn

use of org.hibernate.eclipse.console.model.IRevEngColumn 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();
    }
}
Also used : CheckedTreeSelectionDialog(org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IRevEngColumn(org.hibernate.eclipse.console.model.IRevEngColumn) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) TreeSet(java.util.TreeSet) IRevEngTable(org.hibernate.eclipse.console.model.IRevEngTable) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with IRevEngColumn

use of org.hibernate.eclipse.console.model.IRevEngColumn in project jbosstools-hibernate by jbosstools.

the class ColumnDetailsPage method selectionChanged.

public void selectionChanged(IFormPart part, ISelection selection) {
    IRevEngColumn newColumn = (IRevEngColumn) ((IStructuredSelection) selection).getFirstElement();
    if (column != null) {
        column.removePropertyChangeListener(this);
    }
    if (newColumn != null) {
        newColumn.addPropertyChangeListener(this);
    }
    column = newColumn;
    update();
}
Also used : IRevEngColumn(org.hibernate.eclipse.console.model.IRevEngColumn)

Aggregations

IRevEngColumn (org.hibernate.eclipse.console.model.IRevEngColumn)4 IRevEngTable (org.hibernate.eclipse.console.model.IRevEngTable)3 IRevEngGenerator (org.hibernate.eclipse.console.model.IRevEngGenerator)2 IRevEngPrimaryKey (org.hibernate.eclipse.console.model.IRevEngPrimaryKey)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 IRevEngParameter (org.hibernate.eclipse.console.model.IRevEngParameter)1 LazyDatabaseSchema (org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)1 CheckedTreeSelectionDialog (org.hibernate.eclipse.mapper.editors.reveng.xpl.CheckedTreeSelectionDialog)1 RevEngColumnAdapter (org.hibernate.eclipse.mapper.model.RevEngColumnAdapter)1 RevEngGeneratorAdapter (org.hibernate.eclipse.mapper.model.RevEngGeneratorAdapter)1 RevEngParamAdapter (org.hibernate.eclipse.mapper.model.RevEngParamAdapter)1 RevEngPrimaryKeyAdapter (org.hibernate.eclipse.mapper.model.RevEngPrimaryKeyAdapter)1 RevEngTableAdapter (org.hibernate.eclipse.mapper.model.RevEngTableAdapter)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1