use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class StopDatabaseAction method run.
public void run() {
Object[] objArr = this.getSelectedObj();
if (objArr == null || objArr.length <= 0) {
setEnabled(false);
return;
}
Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
for (int i = 0; objArr != null && i < objArr.length; i++) {
if (!isSupported(objArr[i])) {
setEnabled(false);
return;
}
ISchemaNode schemaNode = (ISchemaNode) objArr[i];
CubridDatabase database = schemaNode.getDatabase();
databaseSet.add(database);
}
StringBuffer dbNames = new StringBuffer();
Iterator<CubridDatabase> it = databaseSet.iterator();
while (it.hasNext()) {
CubridDatabase database = it.next();
dbNames.append(database.getLabel()).append(",");
}
dbNames = new StringBuffer(dbNames.substring(0, dbNames.length() - 1));
boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames.toString()));
if (!isStop) {
return;
}
Iterator<CubridDatabase> iter = databaseSet.iterator();
while (iter.hasNext()) {
CubridDatabase database = iter.next();
final JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
CommonUITool.openWarningBox(Messages.bind(Messages.msgStopDbWithJob, dbName));
databaseSet.remove(database);
continue;
}
}
final Object[] dbObjectArr = new Object[databaseSet.size()];
databaseSet.toArray(dbObjectArr);
ISelectionProvider provider = getSelectionProvider();
final Shell shell = getShell();
if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
final TreeViewer viewer = (TreeViewer) provider;
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
final CubridDatabase database = node.getDatabase();
if (!isSupported(database)) {
continue;
}
monitor.subTask(Messages.bind(Messages.stopDbTaskName, database.getName()));
ITask task = taskList.get(i);
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.STANDALONE);
display.syncExec(new Runnable() {
public void run() {
viewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
boolean isContinue = true;
for (int i = 0; i < dbObjectArr.length; i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
CubridDatabase database = node.getDatabase();
if (!isSupported(database)) {
setEnabled(false);
return;
}
if (!LayoutUtil.checkAllQueryEditor(database)) {
isContinue = false;
break;
}
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
}
if (!isContinue) {
return;
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
ActionManager.getInstance().fireSelectionChanged(getSelection());
for (int i = 0; i < dbObjectArr.length; i++) {
CubridDatabase database = (CubridDatabase) dbObjectArr[i];
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
}
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class EditMonitorDashboardAction method run.
/**
* Open the selected monitoring dash board
*/
public void run() {
Object[] objArr = this.getSelectedObj();
if (objArr == null || objArr.length <= 0) {
setEnabled(false);
return;
}
ICubridNode node = (ICubridNode) objArr[0];
Dashboard dashboard = (Dashboard) node.getAdapter(Dashboard.class);
if (dashboard == null) {
return;
}
AddDashboardDialog dialog = new AddDashboardDialog(getShell());
dialog.setDashboard(dashboard);
int returnCode = dialog.open();
if (returnCode == IDialogConstants.OK_ID) {
node.setId(dashboard.getName());
node.setLabel(dashboard.getName());
MonitorDashboardPersistManager.getInstance().saveDashboard();
ISelectionProvider provider = getSelectionProvider();
if (provider instanceof TreeViewer) {
TreeViewer treeViewer = (TreeViewer) provider;
treeViewer.refresh(node, true);
}
IEditorPart part = LayoutUtil.getEditorPart(node, node.getEditorId());
if (part instanceof MonitorDashboardEditor) {
((MonitorDashboardEditor) part).changePartName(dashboard.getName());
}
} else {
for (int i = 0; i < dashboard.getHostNodeList().size(); i++) {
HostNode hostNode = dashboard.getHostNodeList().get(i);
hostNode.getCopyedHaNodeList().clear();
hostNode.getCopyedHaNodeList().addAll(hostNode.getDbNodeList());
hostNode.getCopyedHaNodeList().addAll(hostNode.getBrokerNodeList());
}
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class AddMonitorDashboardAction method run.
/**
* Open the dialog
*/
public void run() {
AddDashboardDialog dialog = new AddDashboardDialog(getShell());
int returnCode = dialog.open();
if (returnCode == IDialogConstants.OK_ID) {
Dashboard dashboard = dialog.getDashboard();
DefaultCubridNode dashboardNode = new DefaultCubridNode(dashboard.getName(), dashboard.getName(), "icons/navigator/status_item.png");
dashboardNode.setType(CubridNodeType.MONITOR_DASHBOARD);
dashboardNode.setEditorId(MonitorDashboardEditor.ID);
dashboardNode.setModelObj(dashboard);
MonitorDashboardPersistManager.getInstance().addMonitorDashboard(dashboardNode);
ISelectionProvider provider = getSelectionProvider();
if (provider instanceof TreeViewer) {
TreeViewer treeViewer = (TreeViewer) provider;
/*TOOLS-3665 Refresh the input of TreeViewer*/
treeViewer.setInput(CubridMonitorNavigatorView.getTreeViewerInput());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(dashboardNode, CubridNodeChangedEventType.NODE_ADD));
LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(dashboardNode);
}
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class RefreshAction method run.
/**
* Reload the selected CUBRID node
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
return;
}
ICubridNode cubridNode = (ICubridNode) obj[0];
if (cubridNode == null) {
return;
}
String nodeType = cubridNode.getType();
if (NodeType.USER_TABLE.equals(nodeType) || NodeType.SYSTEM_TABLE.equals(nodeType) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(nodeType) || NodeType.USER_PARTITIONED_TABLE.equals(nodeType) || NodeType.SYSTEM_VIEW.equals(nodeType) || NodeType.USER_VIEW.equals(nodeType)) {
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
schemaNode.getDatabase().getDatabaseInfo().removeSchema(cubridNode.getLabel());
}
LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(cubridNode);
ISelectionProvider provider = this.getSelectionProvider();
if ((provider instanceof TreeViewer) && cubridNode != null && cubridNode.isContainer()) {
TreeViewer viewer = (TreeViewer) provider;
CommonUITool.refreshNavigatorTree(viewer, cubridNode);
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class ChangeShardAction method run.
/**
* Reload the selected CUBRID node
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
return;
}
ICubridNode cubridNode = (ICubridNode) obj[0];
if (cubridNode == null) {
return;
}
String nodeType = cubridNode.getType();
if (!NodeType.DATABASE.equals(nodeType)) {
return;
}
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
DatabaseInfo dbInfo = schemaNode.getDatabase().getDatabaseInfo();
if (!dbInfo.isShard()) {
return;
}
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(dbInfo.getCurrentShardId());
dialog.setShardVal(dbInfo.getCurrentShardVal());
dialog.setShardQueryType(dbInfo.getShardQueryType());
if (dialog.open() != IDialogConstants.OK_ID) {
return;
}
int shardId = dialog.getShardId();
int shardVal = dialog.getShardVal();
int shardQueryType = dialog.getShardQueryType();
dbInfo.setCurrentShardId(shardId);
dbInfo.setCurrentShardVal(shardVal);
dbInfo.setShardQueryType(shardQueryType);
ISelectionProvider provider = this.getSelectionProvider();
if ((provider instanceof TreeViewer) && cubridNode != null && cubridNode.isContainer()) {
TreeViewer viewer = (TreeViewer) provider;
CommonUITool.refreshNavigatorTree(viewer, cubridNode);
}
}
Aggregations