use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.
the class AddHostAction method doRun.
public void doRun(Object[] nodes) {
CubridGroupNode parent = getParentGroupNode(nodes);
if (parent == null) {
LOGGER.error("parent is null.");
return;
}
HostDialog dialog = new HostDialog(getShell(), true, false);
int returnCode = dialog.open();
if (returnCode == HostDialog.ADD_ID || returnCode == HostDialog.CONNECT_ID) {
CubridServer server = getServerNode(dialog);
if (server == null) {
LOGGER.error("server is null.");
return;
}
CMHostNodePersistManager.getInstance().addServer(server);
TreeItem item = null;
parent.addChild(server);
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
if (navigatorView != null) {
boolean isShowGroup = navigatorView.isShowGroup();
TreeViewer treeViewer = navigatorView.getViewer();
if (isShowGroup) {
item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
} else {
item = new TreeItem(treeViewer.getTree(), SWT.NONE);
}
CMGroupNodePersistManager.getInstance().saveAllGroupNode();
item.setText(server.getLabel());
item.setData(server);
treeViewer.refresh(server, true);
treeViewer.expandToLevel(server, 1);
treeViewer.setSelection(new StructuredSelection(server), true);
if (returnCode == HostDialog.CONNECT_ID) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
} else {
dialog.closeTestServerConnection();
}
}
}
use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.
the class ConnectHostAction method doRun.
public void doRun(CubridServer[] servers) {
if (servers.length == 0) {
return;
}
if (servers.length == 1) {
CubridServer server = servers[0];
if (server.isAutoSavePassword() && CubridWorkbenchContrItem.connectHost(server.getServerInfo(), true)) {
server.getLoader().setLoaded(false);
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
if (view == null) {
LOGGER.error("view is null.");
return;
}
TreeViewer treeViewer = view.getViewer();
treeViewer.refresh(server, true);
treeViewer.expandToLevel(server, 1);
ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
CubridNodeChangedEvent event = new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED);
CubridNodeManager.getInstance().fireCubridNodeChanged(event);
} else {
EditHostAction editHostAction = (EditHostAction) ActionManager.getInstance().getAction(EditHostAction.ID);
if (editHostAction != null) {
editHostAction.doRun(servers, true);
}
}
} else {
List<FailedHostServerInfo> failedServerList = new ArrayList<FailedHostServerInfo>();
for (CubridServer object : servers) {
CubridServer server = (CubridServer) object;
String errMsg = null;
if (server.isAutoSavePassword()) {
errMsg = CubridWorkbenchContrItem.connectHostWithErrMsg(server.getServerInfo(), false);
} else {
errMsg = "Incorrect or missing password.";
}
if (errMsg == null) {
server.getLoader().setLoaded(false);
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
TreeViewer treeViewer = view.getViewer();
treeViewer.refresh(server, true);
treeViewer.expandToLevel(server, 1);
ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
} else {
failedServerList.add(new FailedHostServerInfo(server, errMsg));
}
}
if (failedServerList.size() > 0) {
NewMultiHostConnectionDialog dialog = new NewMultiHostConnectionDialog(getShell(), failedServerList);
dialog.open();
}
}
}
use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.
the class HostDialog method closeSaveServerConnection.
public void closeSaveServerConnection() {
if (server != null) {
CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
server.removeAllChild();
TreeViewer viewer = (TreeViewer) LayoutManager.getInstance().getSelectionProvider();
viewer.refresh(server);
viewer.setSelection(null, true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.
the class FinishTask method call.
public Integer call() {
ProgressBar bar = (ProgressBar) item.getData(MultiHostConnectionDialog.KEY_BAR);
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
boolean isRunUpdateCmUserTask = false;
BrokerInfos brokerInfos = null;
int size = tasks.size();
int taskIdx = 1;
for (ITask task : tasks) {
if (task instanceof MonitoringTask) {
if (!serverInfo.isConnected()) {
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
MonitoringTask monitoringTask = (MonitoringTask) task;
serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
if (serverInfo.isConnected()) {
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
} else {
CMHostNodePersistManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
}
}
} else if ((task instanceof UpdateCMUserTask)) {
updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0) {
item.setText(3, msg);
disConnect();
isFinished = true;
updateIcon();
return 1;
}
if (task instanceof GetEnvInfoTask) {
GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
serverInfo.setEnvInfo(envInfo);
String clientVersion = getClientVerion();
if (!isClientSupport(clientVersion)) {
item.setText(3, Messages.bind(Messages.errNoSupportServerVersion, clientVersion));
disConnect();
isFinished = true;
updateIcon();
return 2;
}
String jdbcVersion = serverInfo.getJdbcDriverVersion();
if (serverInfo.validateJdbcVersion(jdbcVersion)) {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
}
} else {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
item.setText(3, Messages.errNoSupportDriver);
} else {
item.setText(3, Messages.errSelectSupportDriver);
}
disConnect();
isFinished = true;
updateIcon();
return 3;
}
} else if (task instanceof GetDatabaseListTask) {
GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
if (databaseInfoList != null) {
allDatabaseInfoList.addAll(databaseInfoList);
}
} else if (task instanceof GetCMConfParameterTask) {
GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
ServerType serverType = ServerType.BOTH;
if (confParameters != null) {
String target = confParameters.get(CubridManagerConfParaConstants.CM_TARGET);
if (target != null) {
if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
serverType = ServerType.BOTH;
} else if (target.indexOf("broker") >= 0) {
serverType = ServerType.BROKER;
} else if (target.indexOf("server") >= 0) {
serverType = ServerType.DATABASE;
}
}
}
if (serverInfo != null) {
serverInfo.setServerType(serverType);
}
} else if (task instanceof CommonQueryTask) {
CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
brokerInfos = getBrokerTask.getResultModel();
if (serverInfo != null) {
serverInfo.setBrokerInfos(brokerInfos);
}
} else if (task instanceof GetCMUserListTask) {
if (serverInfo != null && serverInfo.isConnected()) {
GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
ServerUserInfo userInfo = serverUserInfoList.get(i);
if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
serverInfo.setLoginedUserInfo(userInfo);
break;
}
}
List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
if (databaseInfoList != null) {
authDatabaseList.addAll(databaseInfoList);
}
isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
if (isRunUpdateCmUserTask) {
serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
}
}
} else if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
if (serverInfo != null) {
serverInfo.setCubridConfParaMap(confParas);
}
} else if (task instanceof GetBrokerConfParameterTask) {
GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
if (serverInfo != null) {
serverInfo.setBrokerConfParaMap(confParas);
}
} else if (task instanceof FinishTask) {
isSuccess = true;
server.getLoader().setLoaded(false);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
bar.setSelection(taskIdx++ / size * 100);
if (isCanceled()) {
isFinished = true;
updateIcon();
return 4;
}
}
bar.setSelection(100);
item.setText(3, Messages.msgConneted);
isFinished = true;
return 0;
}
use of com.cubrid.common.ui.spi.event.CubridNodeChangedEvent in project cubrid-manager by CUBRID.
the class HostDialog method buttonPressed.
/**
* Call this method when button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == HostDialog.TEST_CONNECT_ID || buttonId == HostDialog.ADD_ID || buttonId == HostDialog.CONNECT_ID || buttonId == HostDialog.SAVE_ID) {
String hostName = hostNameText.getText();
String address = addressText.getText();
String port = portText.getText();
String userName = userNameText.getText();
String password = passwordText.getText();
String jdbcDriverVersion = jdbcVersionCombo.getText();
serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(address, Integer.parseInt(port), userName);
if (serverInfo == null) {
serverInfo = new ServerInfo();
serverInfo.setHostAddress(address);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
serverInfo.setUserName(userName);
} else {
//use a new ServerInfo instance, and never change the existing ServerInfo. for UX improvement.
if (buttonId == HostDialog.TEST_CONNECT_ID) {
serverInfo = new ServerInfo();
serverInfo.setHostAddress(address);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
serverInfo.setUserName(userName);
}
}
serverInfo.setUserPassword(password);
serverInfo.setServerName(hostName);
serverInfo.setJdbcDriverVersion(jdbcDriverVersion);
if (btnUseTimeOut.getSelection()) {
int index = timeOutCombo.getSelectionIndex();
serverInfo.setSoTimeOut(soTimeOutValues[index]);
}
}
//use the serverInfo as testing connection server info.
testConnServerInfo = serverInfo;
if (buttonId == HostDialog.CONNECT_ID) {
//must release current connection first.
closeTestServerConnection();
connect(buttonId);
if (GeneralPreference.isUseHostDashboard() && serverInfo != null && serverInfo.isConnected()) {
((HostDashboardAction) ActionManager.getInstance().getAction(HostDashboardAction.ID)).doRun(serverInfo);
}
} else if (buttonId == HostDialog.TEST_CONNECT_ID) {
//must release current connection first.
closeTestServerConnection();
connect(buttonId);
} else if (buttonId == HostDialog.ADD_ID) {
/*Save operate at the action*/
QueryOptions.setAutoCommit(serverInfo, btnAutoCommit.getSelection());
closeSaveServerConnection();
setReturnCode(buttonId);
close();
} else if (buttonId == HostDialog.SAVE_ID) {
CommonUITool.openInformationBox(Messages.msgSaveAndClose);
server.setLabel(serverInfo.getServerName());
/*Save operate at the action*/
QueryOptions.setAutoCommit(serverInfo, btnAutoCommit.getSelection());
/*For bug There is no error message after saving the wrong password.*/
HostUtils.processHostDisconnected(server);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
closeSaveServerConnection();
setReturnCode(buttonId);
close();
} else {
setReturnCode(buttonId);
close();
}
}
Aggregations