Search in sources :

Example 76 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class TableToPhpCodeAction method doRun.

/**
	 * Perform all tables
	 *
	 * @param obj
	 */
private void doRun(final Object[] obj) {
    final File filepath = TableUtil.getSavedDirForCreateCodes(getShell(), null);
    if (filepath == null) {
        return;
    }
    if (!CommonUITool.openConfirmBox(Messages.msgConfirmTableToCode)) {
        return;
    }
    final Map<CubridDatabase, Connection> connections = new HashMap<CubridDatabase, Connection>();
    try {
        final Display display = PlatformUI.getWorkbench().getDisplay();
        BusyIndicator.showWhile(display, new Runnable() {

            public void run() {
                // FIXME move this logic to core module
                StringBuilder notExportedList = new StringBuilder();
                for (int i = 0; i < obj.length; i++) {
                    DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
                    Connection connection = connections.get(table.getDatabase());
                    if (connection == null) {
                        try {
                            connection = JDBCConnectionManager.getConnection(table.getDatabase().getDatabaseInfo(), true);
                            connections.put(table.getDatabase(), connection);
                        } catch (Exception e) {
                            LOGGER.error(e.getMessage(), e);
                        }
                    }
                    if (connection == null) {
                        if (notExportedList.length() > 0) {
                            notExportedList.append(", ");
                        }
                        notExportedList.append(table.getName());
                        continue;
                    }
                    String pojoClassFileName = getPojoFileName(table);
                    String pojoClassData = getPojoString(connection, table);
                    String pojoClassPath = filepath.getAbsolutePath() + File.separator + pojoClassFileName;
                    //TODO: error handling
                    boolean result = FileUtil.writeToFile(pojoClassPath, pojoClassData, "utf-8");
                    if (!result) {
                        if (notExportedList.length() > 0) {
                            notExportedList.append(", ");
                        }
                        notExportedList.append(table.getName());
                    }
                }
                finishNotice(notExportedList.toString());
            }
        });
    } finally {
        Collection<Connection> items = connections.values();
        for (Connection conn : items) {
            QueryUtil.freeQuery(conn);
        }
    }
}
Also used : HashMap(java.util.HashMap) Connection(java.sql.Connection) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 77 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class ReformatColumnsAliasDialog method open.

public String open() {
    createContents();
    CommonUITool.centerShell(shell);
    shell.open();
    shell.layout();
    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return resultAliasText;
}
Also used : Display(org.eclipse.swt.widgets.Display)

Example 78 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class CubridUserTableIndexLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetUserClassIndexesTask task = new GetUserClassIndexesTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        String tableName = parent.getParent().getLabel();
        List<TableIndex> indexes = task.getIndexesNames(tableName);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        String parentId = parent.getId();
        if (indexes != null && !indexes.isEmpty()) {
            for (TableIndex index : indexes) {
                String indexName = index.getIndexName();
                String nodeId = parentId + NODE_SEPARATOR + indexName;
                String label = indexName;
                List<String> dependColumns = index.getColumns();
                if (dependColumns != null && !dependColumns.isEmpty()) {
                    String keyAttrName = index.getColumns().toString();
                    label += keyAttrName.replace('[', '(').replace(']', ')');
                }
                ICubridNode node = new DefaultSchemaNode(nodeId, label, "icons/navigator/table_index_item.png");
                if (index.isPrimaryKey()) {
                    node.setIconPath("icons/primary_key.png");
                }
                node.setType(NodeType.TABLE_INDEX);
                node.setModelObj(index);
                node.setContainer(false);
                parent.addChild(node);
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TableIndex(com.cubrid.cubridmanager.core.cubrid.table.model.TableIndex) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) GetUserClassIndexesTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetUserClassIndexesTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Display(org.eclipse.swt.widgets.Display)

Example 79 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class CubridPartitionedTableLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetPartitionedClassListTask task = new GetPartitionedClassListTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        List<ClassInfo> classInfoList = task.getAllPartitionedClassInfoList(parent.getLabel());
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        if (classInfoList != null && !classInfoList.isEmpty()) {
            for (ClassInfo clasInfo : classInfoList) {
                String id = parent.getId() + NODE_SEPARATOR + clasInfo.getClassName();
                ICubridNode partitionedClassNode = new DefaultSchemaNode(id, clasInfo.getClassName(), "icons/navigator/schema_table_item.png");
                partitionedClassNode.setType(NodeType.USER_PARTITIONED_TABLE);
                partitionedClassNode.setModelObj(clasInfo);
                partitionedClassNode.setContainer(false);
                partitionedClassNode.setEditorId(SchemaInfoEditorPart.ID);
                parent.addChild(partitionedClassNode);
            }
        }
        database.getDatabaseInfo().addPartitionedTableList(parent.getLabel(), classInfoList);
        Collections.sort(parent.getChildren());
        loadColumns(parent, getLevel(), monitor);
        loadIndexes(parent, getLevel(), monitor);
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) GetPartitionedClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetPartitionedClassListTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) Display(org.eclipse.swt.widgets.Display)

Example 80 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class CubridNodeLoader method openErrorBox.

/**
	 * 
	 * Open the error box
	 * 
	 * @param msg the error message
	 */
protected void openErrorBox(final String msg) {
    Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        public void run() {
            if (msg != null && msg.trim().length() > 0) {
                CommonUITool.openErrorBox(msg);
            }
        }
    });
}
Also used : Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23