use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class RemoveAllDbLogAction method run.
/**
* Remove all database logs
*/
public void run() {
if (!CommonUITool.openConfirmBox(Messages.warningRemoveLog)) {
return;
}
Object[] selected = this.getSelectedObj();
DelAllLogTask delAllLogTask = new DelAllLogTask(((DefaultCubridNode) selected[0]).getServer().getServerInfo());
String[] path = new String[((DefaultCubridNode) selected[0]).getChildren().size()];
//get last file name
String lastDBLog = "";
LogInfo currLogFile;
for (int i = 0, len = path.length; i < len; i++) {
currLogFile = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class)));
if (lastDBLog.compareTo(currLogFile.getPath()) < 0) {
lastDBLog = currLogFile.getPath();
}
}
for (int i = 0, len = path.length - 1; i < len; i++) {
if (!((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath().equals(lastDBLog)) {
path[i] = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath();
}
}
delAllLogTask.setPath(path);
TaskExecutor taskExecutor = new CommonTaskExec(Messages.removeLogTaskName);
taskExecutor.addTask(delAllLogTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (!taskExecutor.isSuccess()) {
return;
}
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
DefaultCubridNode delNode = ((DefaultCubridNode) selected[0]);
ICubridNode parentNode = delNode.getParent().getParent();
parentNode.removeChild(delNode);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPage activePage = window.getActivePage();
for (int i = 0, len = path.length; i < len; i++) {
IEditorPart editor = activePage.findEditor(((DefaultCubridNode) selected[0]).getChildren().get(i));
if (!((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath().equals(lastDBLog)) {
treeViewer.remove(((DefaultCubridNode) selected[0]).getChildren().get(i));
if (null != editor) {
activePage.closeEditor(editor, true);
}
}
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class RemoveAllErrorLogAction method isSupported.
/**
* @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
* .lang.Object)
* @param obj Object
* @return boolean(whether to support)
*/
public boolean isSupported(Object obj) {
if (obj instanceof ICubridNode) {
ICubridNode node = (ICubridNode) obj;
if (node.getServer() == null) {
return false;
}
ServerUserInfo serverUserInfo = node.getServer().getServerInfo().getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return false;
}
if (CubridNodeType.LOGS_BROKER_ERROR_LOG_FOLDER.equals(node.getType())) {
return true;
}
}
return false;
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class RemoveAllErrorLogAction method run.
/**
* Remove all error logs
*/
public void run() {
if (!CommonUITool.openConfirmBox(Messages.warningRemoveLog)) {
return;
}
Object[] selected = this.getSelectedObj();
DelAllLogTask delAllLogTask = new DelAllLogTask(((DefaultCubridNode) selected[0]).getServer().getServerInfo());
String[] path = new String[((DefaultCubridNode) selected[0]).getChildren().size()];
for (int i = 0, len = path.length; i < len; i++) {
path[i] = ((LogInfo) (((DefaultCubridNode) selected[0]).getChildren().get(i).getAdapter(LogInfo.class))).getPath();
}
delAllLogTask.setPath(path);
TaskExecutor taskExecutor = new CommonTaskExec(Messages.removeLogTaskName);
taskExecutor.addTask(delAllLogTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess()) {
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
DefaultCubridNode delNode = ((DefaultCubridNode) selected[0]);
ICubridNode parentNode = delNode.getParent().getParent();
parentNode.removeChild(delNode);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = window.getActivePage();
for (int i = 0, len = path.length; i < len; i++) {
IEditorPart editor = activePage.findEditor(((DefaultCubridNode) selected[0]).getChildren().get(i));
treeViewer.remove(((DefaultCubridNode) selected[0]).getChildren().get(i));
if (null != editor) {
activePage.closeEditor(editor, true);
}
}
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class RemoveAllManagerLogAction method isSupported.
/**
* @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
* .lang.Object)
* @param obj Object
* @return boolean(whether to support)
*/
public boolean isSupported(Object obj) {
if (obj instanceof ICubridNode) {
ICubridNode node = (ICubridNode) obj;
if (node.getServer() == null) {
return false;
}
ServerUserInfo serverUserInfo = node.getServer().getServerInfo().getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return false;
}
if (CubridNodeType.LOGS_MANAGER_ACCESS_LOG.equals(node.getType()) || CubridNodeType.LOGS_MANAGER_ERROR_LOG.equals(node.getType())) {
return true;
}
}
return false;
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class AddFunctionAction method run.
/**
* Open addFunctionDialog
*/
public void run() {
// FIXME logic code move to core module
Shell shell = getShell();
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
CubridDatabase database = node.getDatabase();
EditFunctionDialog dlg = new EditFunctionDialog(shell);
dlg.setDatabase(database);
dlg.setNewFlag(true);
ISelectionProvider provider = getSelectionProvider();
if (dlg.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.SP_FOLDER_ID);
folderNode = folderNode.getChild(folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.FUNCTION_FOLDER_ID);
TreeViewer treeViewer = (TreeViewer) provider;
if (folderNode == null || !folderNode.getLoader().isLoaded()) {
return;
}
String functionName = dlg.getFunctionName().toLowerCase(Locale.getDefault());
String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + functionName;
DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
SPInfo spInfo = new SPInfo(functionName);
spInfo.setOwner(userInfo.getName());
ICubridNode newNode = CubridFunctionFolderLoader.createFunctionNode(id, spInfo);
CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
}
}
Aggregations