Search in sources :

Example 46 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class PropertyViewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    dialog.setPropertyQuery(true);
    dialog.open();
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 47 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class AddFKDialog method getPKTableData.

/**
	 * Get PK Table Data
	 * 
	 */
private void getPKTableData() {
    pkForeignTable.removeAll();
    if (oldCombo != null) {
        oldCombo.dispose();
    }
    String refTable = foreignTableCombo.getText();
    refSchema = getSchemaInfo(refTable);
    if (refSchema == null) {
        return;
    }
    List<SchemaInfo> supers = getRefedSupper(refSchema);
    Constraint pk = refSchema.getPK(supers);
    if (pk != null) {
        List<String> pkAttrs = pk.getAttributes();
        for (String attr : pkAttrs) {
            DBAttribute da = (DBAttribute) refSchema.getDBAttributeByName(attr, false);
            if (da == null) {
                continue;
            }
            TableItem item = new TableItem(pkForeignTable, SWT.NONE);
            item.setText(0, da.getName());
            item.setText(1, DataType.getShownType(da.getType()));
        }
    }
    if (fkTable.getItemCount() > 0) {
        TableItem[] items = fkTable.getItems();
        for (int i = 0, n = items.length; i < n; i++) {
            //$NON-NLS-1$
            items[i].setText(fkTableColCount - 1, "");
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 48 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method createPartControl.

public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));
    ToolBar toolBar = new ToolBar(parent, SWT.LEFT_TO_RIGHT | SWT.FLAT);
    toolBar.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    ToolItem refreshItem = new ToolItem(toolBar, SWT.PUSH);
    refreshItem.setText(Messages.tablesDetailInfoPartRefreshBtn);
    refreshItem.setToolTipText(Messages.tablesDetailInfoPartBtnRefreshTip);
    refreshItem.setImage(CommonUIPlugin.getImage("icons/action/refresh.png"));
    refreshItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            refresh();
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem countItem = new ToolItem(toolBar, SWT.PUSH);
    countItem.setText(Messages.tablesDetailInfoPartBtnEsitmateRecord);
    countItem.setToolTipText(Messages.tablesDetailInfoPartBtnEsitmateRecordTip);
    countItem.setImage(CommonUIPlugin.getImage("icons/action/count.gif"));
    countItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            List<TableDetailInfo> list = new ArrayList<TableDetailInfo>();
            TableItem[] items = tableListView.getTable().getSelection();
            for (TableItem item : items) {
                list.add((TableDetailInfo) item.getData());
            }
            // Check selected size and confirm
            if (list.size() == 0) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartAlertNotSelected);
                return;
            }
            if (CommonUITool.openConfirmBox(Messages.tablesDetailInfoPartBtnEsitmateRecordAlert)) {
                LoadTableRecordCountsProgress progress = new LoadTableRecordCountsProgress(database, list);
                progress.getTableCounts();
                tableListView.refresh();
            }
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem viewDataItem = new ToolItem(toolBar, SWT.PUSH);
    viewDataItem.setText(Messages.tablesDetailInfoPartBtnViewData);
    viewDataItem.setToolTipText(Messages.tablesDetailInfoPartBtnViewDataTip);
    viewDataItem.setImage(CommonUIPlugin.getImage("icons/action/table_select_all.png"));
    viewDataItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = tableListView.getTable().getSelection();
            if (items.length == 1) {
                TableDetailInfo tableDetailInfo = (TableDetailInfo) items[0].getData();
                String query = SQLGenerateUtils.getSelectSQLWithLimit(tableDetailInfo.getTableName(), 1, 100);
                QueryEditorUtil.openQueryEditorAndRunQuery(database, query, true, true);
            } else {
                CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnViewDataSelectOne);
            }
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem copyTableNamesItem = new ToolItem(toolBar, SWT.PUSH);
    copyTableNamesItem.setText(Messages.tablesDetailInfoPartBtnCopyTableNames);
    copyTableNamesItem.setToolTipText(Messages.tablesDetailInfoPartBtnCopyTableNamesTip);
    copyTableNamesItem.setImage(CommonUIPlugin.getImage("icons/action/copy_table_name.gif"));
    copyTableNamesItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            List<String> nameList = new ArrayList<String>();
            for (TableDetailInfo tablesDetailInfoPOJO : tableList) {
                nameList.add(tablesDetailInfoPOJO.getTableName());
            }
            if (nameList.size() == 0) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartBtnCopySuccessFailed);
                return;
            }
            copyNamesToClipboard(nameList);
            CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnCopySuccessTitle, Messages.tablesDetailInfoPartBtnCopySuccessMsg);
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    ToolItem copyColumnNamesItem = new ToolItem(toolBar, SWT.PUSH);
    copyColumnNamesItem.setText(Messages.tablesDetailInfoPartBtnCopyColumnNames);
    copyColumnNamesItem.setToolTipText(Messages.tablesDetailInfoPartBtnCopyColumnNamesTip);
    copyColumnNamesItem.setImage(CommonUIPlugin.getImage("icons/action/copy_column_name.gif"));
    copyColumnNamesItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TablesDetailInfoCTabItem tabItem = (TablesDetailInfoCTabItem) tabFolder.getSelection();
            schemaInfo = tabItem.getTableInfoComposite().getData();
            if (schemaInfo == null) {
                CommonUITool.openWarningBox(Messages.tablesDetailInfoPartBtnCopySuccessFailed);
                return;
            }
            List<String> nameList = new ArrayList<String>();
            for (DBAttribute att : schemaInfo.getAttributes()) {
                nameList.add(att.getName());
            }
            copyNamesToClipboard(nameList);
            CommonUITool.openInformationBox(Messages.tablesDetailInfoPartBtnCopySuccessTitle, Messages.tablesDetailInfoPartBtnCopySuccessMsg);
        }
    });
    new ToolItem(toolBar, SWT.SEPARATOR);
    final NewTableAction newTableAction = (NewTableAction) ActionManager.getInstance().getAction(NewTableAction.ID);
    ToolItem newTableItem = new ToolItem(toolBar, SWT.PUSH);
    newTableItem.setText(newTableAction.getText());
    newTableItem.setImage(CommonUITool.getImage(newTableAction.getImageDescriptor()));
    newTableItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            newTableAction.run(database);
        }
    });
    ScrolledComposite scrolledComp = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComp.setLayout(new FillLayout());
    scrolledComp.setExpandHorizontal(true);
    scrolledComp.setExpandVertical(true);
    scrolledComp.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    topSash = new SashForm(scrolledComp, SWT.VERTICAL);
    topSash.setBackground(ResourceManager.getColor(136, 161, 227));
    GridLayout gridLayout = new GridLayout();
    gridLayout.verticalSpacing = 0;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.horizontalSpacing = 0;
    topSash.setLayout(gridLayout);
    topSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    topSash.SASH_WIDTH = 1;
    scrolledComp.setContent(topSash);
    createTablesDetailInfoTable(topSash);
    createTabFolder(topSash);
    topSash.setWeights(new int[] { 70, 30 });
    this.setInputs();
}
Also used : TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) NewTableAction(com.cubrid.common.ui.cubrid.table.action.NewTableAction) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ArrayList(java.util.ArrayList) List(java.util.List) LoadTableRecordCountsProgress(com.cubrid.common.ui.spi.progress.LoadTableRecordCountsProgress) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 49 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class TableDashboardComposite method copyTablesDetailToClipboard.

public void copyTablesDetailToClipboard() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final Clipboard cb = new Clipboard(shell.getDisplay());
    StringBuilder sb = new StringBuilder();
    List<Integer> selectIndex = new ArrayList<Integer>();
    SchemaInfo schema = (SchemaInfo) columnTableView.getInput();
    List<DBAttribute> list = schema.getAttributes();
    for (int i = 0; i < columnTableView.getTable().getSelectionIndices().length; i++) {
        selectIndex.add(columnTableView.getTable().getSelectionIndices()[i]);
    }
    for (int i = 0; i < selectIndex.size(); i++) {
        if (i != 0) {
            sb.append(StringUtil.NEWLINE);
        }
        DBAttribute attr = list.get(i);
        sb.append(attr.getName());
    }
    TextTransfer textTransfer = TextTransfer.getInstance();
    Transfer[] transfers = new Transfer[] { textTransfer };
    Object[] data = new Object[] { sb.toString() };
    cb.setContents(data, transfers);
    cb.dispose();
}
Also used : ArrayList(java.util.ArrayList) Shell(org.eclipse.swt.widgets.Shell) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 50 with DBAttribute

use of com.cubrid.common.core.common.model.DBAttribute in project cubrid-manager by CUBRID.

the class CreateViewDialog method init.

/**
	 * initializes some values
	 */
private void init() {
    String ownerOld = null;
    fillOwnerCombo();
    if (isNewTableFlag) {
        tableText.setText("");
        tableText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent event) {
                valid();
            }
        });
        ownerOld = database.getUserName();
        setTitle(Messages.newViewMsgTitle);
        setMessage(Messages.newViewMsg);
        getShell().setText(Messages.newViewShellTitle);
    } else {
        if (classInfo == null) {
            return;
        }
        tableText.setEditable(false);
        tableText.setText(classInfo.getClassName());
        if (isCommentSupport) {
            if (!classInfo.isSystemClass()) {
                String comment = getViewComment();
                if (comment != null) {
                    viewDescriptionText.setText(comment);
                }
            } else {
                viewDescriptionText.setEditable(false);
            }
        }
        ownerOld = classInfo.getOwnerName();
        String[] strs = new String[] { classInfo.getClassName(), isPropertyQuery ? Messages.msgPropertyInfo : Messages.msgEditInfo };
        setTitle(Messages.bind(Messages.editViewMsgTitle, strs));
        setMessage(Messages.editViewMsg);
        strs = new String[] { classInfo.getClassName(), isPropertyQuery ? Messages.msgPropertyInfo : Messages.msgEditInfo };
        String title = Messages.bind(Messages.editViewShellTitle, strs);
        getShell().setText(title);
        for (String sql : vclassList) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", sql);
            queryListData.add(map);
        }
        if (!vclassList.isEmpty()) {
            querydescText.setText(formatSql(vclassList.get(0)));
        }
        // "Name", "Data type", "Default type", "Default value"
        for (DBAttribute attr : attrList) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", attr.getName());
            String type = attr.getType();
            if (type.startsWith(DATATYPE_VARNCHAR)) {
                type = type.replaceAll(DATATYPE_VARNCHAR, DataType.DATATYPE_NCHAR_VARYING);
            }
            if (type.startsWith(DATATYPE_VARBIT)) {
                type = type.replaceAll(DATATYPE_VARBIT, DataType.DATATYPE_BIT_VARYING);
            }
            if (DataType.DATATYPE_OBJECT.equalsIgnoreCase(type)) {
                if (attr.getDomainClassName() == null || "".equals(attr.getDomainClassName())) {
                    type = DataType.DATATYPE_OBJECT;
                } else {
                    type = attr.getDomainClassName();
                }
            }
            map.put("1", type);
            map.put("2", defaultType[0]);
            map.put("3", defaultType[0]);
            if (isCommentSupport) {
                map.put("4", attr.getDescription());
            }
            String dfltType = null;
            String value = null;
            if (attr.getDefault() != null && !attr.getDefault().equals("")) {
                if (attr.isShared()) {
                    dfltType = defaultType[1];
                } else {
                    dfltType = defaultType[2];
                }
                value = attr.getDefault();
            }
            if (value == null) {
                value = "";
            }
            if (type != null && (type.startsWith(DataType.DATATYPE_CHAR) || type.startsWith(DataType.DATATYPE_STRING) || type.startsWith(DataType.DATATYPE_VARCHAR)) && (value.startsWith("'") && value.endsWith("'") && value.length() > 1)) {
                value = value.substring(1, value.length() - 1);
            }
            map.put("2", dfltType);
            map.put("3", value);
            viewColListData.add(map);
        }
        viewColTableViewer.refresh();
        for (int i = 0; i < viewColTableViewer.getTable().getColumnCount(); i++) {
            viewColTableViewer.getTable().getColumn(i).pack();
        }
        queryTableViewer.getTable().select(0);
    }
    for (int i = 0; i < ownerCombo.getItemCount(); i++) {
        String ownerNew = ownerCombo.getItem(i);
        boolean isSame = StringUtil.isEqualIgnoreCase(ownerNew, ownerOld);
        if (isSame) {
            ownerCombo.select(i);
            break;
        }
    }
    queryTableViewer.refresh();
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) HashMap(java.util.HashMap) DBAttribute(com.cubrid.common.core.common.model.DBAttribute)

Aggregations

DBAttribute (com.cubrid.common.core.common.model.DBAttribute)130 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)57 Constraint (com.cubrid.common.core.common.model.Constraint)53 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)16 List (java.util.List)15 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)14 TableItem (org.eclipse.swt.widgets.TableItem)13 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)10 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 Map (java.util.Map)8 Point (org.eclipse.swt.graphics.Point)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)7 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)6 DBResolution (com.cubrid.common.core.common.model.DBResolution)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)5