use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.
the class CQBDbConnectionLoader method addViewFolder.
/**
* Add view folder
*
* @param monitor the IProgressMonitor
* @param database the CubridDatabase
*/
private void addViewFolder(final IProgressMonitor monitor, CubridDatabase database) {
String viewsFolderId = database.getId() + NODE_SEPARATOR + VIEWS_FOLDER_ID;
ICubridNode viewsFolder = database.getChild(viewsFolderId);
if (viewsFolder == null) {
viewsFolder = new DefaultSchemaNode(viewsFolderId, VIEWS_FOLDER_NAME, "icons/navigator/schema_view.png");
viewsFolder.setType(NodeType.VIEW_FOLDER);
viewsFolder.setContainer(true);
ICubridNodeLoader loader = new CubridViewsFolderLoader();
loader.setLevel(getLevel());
viewsFolder.setLoader(loader);
database.addChild(viewsFolder);
if (getLevel() == DEFINITE_LEVEL) {
viewsFolder.getChildren(monitor);
}
} else {
if (viewsFolder.getLoader() != null && viewsFolder.getLoader().isLoaded()) {
viewsFolder.getLoader().setLoaded(false);
viewsFolder.getChildren(monitor);
}
}
}
use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.
the class CQBDbUsersFolderLoader 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.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DbUserInfoList dbUserInfoList = new DbUserInfoList();
GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
parent.removeAllChild();
try {
dbUserInfoList = task.getResultModel();
} catch (Exception e) {
LOGGER.error("load user failed", e);
}
DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
formatUserList(dbUserList);
for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
DbUserInfo dbUserInfo = dbUserList.get(i);
if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
// databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
}
String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
dbUserInfoNode.setType(NodeType.USER);
dbUserInfoNode.setModelObj(dbUserInfo);
dbUserInfoNode.setContainer(false);
dbUserInfoNode.setEditorId(CQBUserEditor.ID);
parent.addChild(dbUserInfoNode);
}
databaseInfo.setDbUserInfoList(dbUserInfoList);
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.
the class CopyPOJOToClipboard method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
final Display display = PlatformUI.getWorkbench().getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
DefaultSchemaNode table = (DefaultSchemaNode) obj[0];
String pojoString = getPojoString(table);
CommonUITool.copyContentToClipboard(pojoString);
CommonUITool.openInformationBox(Messages.titleCopyToPojo, Messages.msgCopyToPojo);
}
});
}
use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.
the class ColumnProposalAdvisor method nodeChanged.
/**
* Perform node changed event
*/
public void nodeChanged(CubridNodeChangedEvent event) {
ICubridNode cubridNode = event.getCubridNode();
CubridNodeChangedEventType eventType = event.getType();
if (cubridNode == null || eventType == null) {
return;
}
if ((NodeType.USER_TABLE.equals(cubridNode.getType()) || NodeType.USER_VIEW.equals(cubridNode.getType())) && cubridNode instanceof DefaultSchemaNode) {
DefaultSchemaNode schemaNode = (DefaultSchemaNode) cubridNode;
DatabaseInfo databaseInfo = schemaNode.getDatabase().getDatabaseInfo();
if (CubridNodeChangedEventType.NODE_REMOVE.equals(eventType)) {
removeTable(databaseInfo, schemaNode.getName());
} else if (CubridNodeChangedEventType.NODE_ADD.equals(eventType) || CubridNodeChangedEventType.NODE_REFRESH.equals(eventType)) {
refreshTable(databaseInfo, schemaNode.getName());
}
}
if (NodeType.DATABASE.equals(cubridNode.getType()) && cubridNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) cubridNode;
if (CubridNodeChangedEventType.DATABASE_LOGIN.equals(eventType)) {
removeProposal(database.getDatabaseInfo());
findProposal(database.getDatabaseInfo());
}
if (CubridNodeChangedEventType.DATABASE_LOGOUT.equals(eventType)) {
removeProposal(database.getDatabaseInfo());
}
if (CubridNodeChangedEventType.CONTAINER_NODE_REFRESH.equals(eventType)) {
removeProposal(database.getDatabaseInfo());
findProposal(database.getDatabaseInfo());
}
}
if (NodeType.TABLE_FOLDER.equals(cubridNode.getType()) || NodeType.VIEW_FOLDER.equals(cubridNode.getType()) && CubridNodeChangedEventType.CONTAINER_NODE_REFRESH.equals(eventType) && cubridNode instanceof DefaultSchemaNode) {
DefaultSchemaNode schemaNode = (DefaultSchemaNode) cubridNode;
removeProposal(schemaNode.getDatabase().getDatabaseInfo());
findProposal(schemaNode.getDatabase().getDatabaseInfo());
}
}
use of com.cubrid.common.ui.spi.model.DefaultSchemaNode in project cubrid-manager by CUBRID.
the class CopySQLToFileDialog method okPressed.
/**
* OK button pressed. Save SQL to file.
*/
protected void okPressed() {
// FIXME move this logic to core module
final int len = objects.length;
final Display display = PlatformUI.getWorkbench().getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
StringBuffer allTableSql = new StringBuffer();
if (btnCreateSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getCreateSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (btnGrantSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getGrantSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (btnInsertSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getInsertSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (btnUpdateSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getUpdateSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (btnDeleteSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getDeleteSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (btnSelectSQL.getSelection()) {
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = SQLGenerateUtils.getSelectSQL(table);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
}
if (allTableSql.length() == 0) {
return;
}
File file = new File(txtFile.getText());
if (file.isDirectory()) {
return;
}
try {
if (!file.delete() && !file.createNewFile()) {
return;
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(allTableSql.toString().getBytes("utf-8"));
fos.flush();
fos.close();
} catch (IOException e) {
LOGGER.error("", e);
}
}
});
super.okPressed();
}
Aggregations