use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class DeleteSerialAction method run.
/**
* Delete the selected serials
*/
public void run(ISchemaNode[] nodeArray) {
if (nodeArray == null) {
LOGGER.error("The nodeArray parameter is a null.");
return;
}
final List<String> serialNameList = new ArrayList<String>();
final StringBuffer serialNames = new StringBuffer();
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
if (!isSupported(nodeArray[i])) {
setEnabled(false);
return;
}
ISchemaNode schemaNode = (ISchemaNode) nodeArray[i];
if (i == 0) {
serialNames.append(schemaNode.getLabel());
}
serialNameList.add(schemaNode.getLabel());
}
if (nodeArray.length > 1) {
serialNames.append(", ...");
}
String cfmMsg = Messages.bind(Messages.msgConfirmDelSerial, serialNames.toString(), nodeArray.length);
boolean isDelete = CommonUITool.openConfirmBox(getShell(), cfmMsg);
if (!isDelete) {
return;
}
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.delSerialTaskName, serialNames.toString());
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
if (task instanceof DeleteSerialTask) {
DeleteSerialTask deleteSerialTask = (DeleteSerialTask) task;
String[] serialNames = new String[serialNameList.size()];
deleteSerialTask.deleteSerial(serialNameList.toArray(serialNames));
}
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
ISchemaNode schemaNode = (ISchemaNode) nodeArray[0];
CubridDatabase database = schemaNode.getDatabase();
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DeleteSerialTask deleteSerialTask = new DeleteSerialTask(databaseInfo);
taskExcutor.addTask(deleteSerialTask);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = schemaNode.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
parent.removeChild((ICubridNode) nodeArray[i]);
}
viewer.remove(parent, nodeArray);
viewer.setSelection(new StructuredSelection(parent), true);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class DropTriggerAction method run.
public void run(ISchemaNode[] nodeArray) {
// FIXME move this logic to core module
if (nodeArray == null) {
LOGGER.error("The nodeArray is a null.");
return;
}
List<String> triggerNameList = new ArrayList<String>();
StringBuffer bf = new StringBuffer();
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
DefaultSchemaNode trigger = (DefaultSchemaNode) nodeArray[i];
triggerNameList.add(trigger.getName());
if (i == 0) {
bf.append(trigger.getName());
}
}
if (nodeArray.length > 1) {
bf.append(", ...");
}
String cfmMsg = Messages.bind(Messages.dropTriggerWarnMSG1, nodeArray.length, bf.toString());
boolean ret = CommonUITool.openConfirmBox(cfmMsg);
if (!ret) {
return;
}
ISchemaNode triggerNode = (ISchemaNode) nodeArray[0];
CommonSQLExcuterTask task = new CommonSQLExcuterTask(triggerNode.getDatabase().getDatabaseInfo());
for (String triggerName : triggerNameList) {
String sql = "DROP TRIGGER " + QuerySyntax.escapeKeyword(triggerName);
task.addSqls(sql);
}
String taskName = Messages.bind(Messages.dropTriggerTaskName, bf.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (!taskExecutor.isSuccess()) {
return;
}
String title = com.cubrid.common.ui.common.Messages.titleSuccess;
String msg = Messages.dropTriggerSuccessMsg;
CommonUITool.openInformationBox(title, msg);
ISelectionProvider provider = this.getSelectionProvider();
ICubridNode parent = triggerNode.getParent();
if (provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
for (int i = 0; nodeArray != null && i < nodeArray.length; i++) {
parent.removeChild((ISchemaNode) nodeArray[i]);
}
viewer.remove(parent, nodeArray);
viewer.setSelection(new StructuredSelection(parent), true);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent);
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class QueryTunerAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
ISelectionProvider provider = getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
String query = getQuery();
if (StringUtil.isNotEmpty(query)) {
new QueryTunerDialog(getShell(), node.getDatabase(), query).open();
} else {
CommonUITool.openInformationBox(Messages.errSelectQueryForTuning);
new QueryTunerDialog(getShell(), node.getDatabase()).open();
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class HiddenElementAction method run.
/**
* Hidden the elements
*/
public void run() {
Object[] objArr = this.getSelectedObj();
if (!isSupported(objArr)) {
setEnabled(false);
return;
}
ISelectionProvider provider = this.getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
List<String> idGrayList = new ArrayList<String>();
List<String> idList = new ArrayList<String>();
for (Object obj : objArr) {
if (obj instanceof ICubridNode) {
ICubridNode node = (ICubridNode) obj;
idList.add(node.getId());
addParentToGrayFilter(idGrayList, node.getParent());
}
}
NodeFilterManager.getInstance().addIdFilterList(idList);
NodeFilterManager.getInstance().addIdGrayFilterList(idGrayList);
TreeViewer viewer = (TreeViewer) provider;
viewer.setFilters(NodeFilterManager.getInstance().getViewerFilter());
}
use of org.eclipse.jface.viewers.ISelectionProvider in project cubrid-manager by CUBRID.
the class ChangeManagerPasswordAction method run.
/**
* Open change password dialog and change CUBRID Manager user password
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
return;
}
ICubridNode node = (ICubridNode) obj[0];
CubridServer server = node.getServer();
ChangePasswordDialog changePasswordDialog = new ChangePasswordDialog(getShell(), false);
changePasswordDialog.setServerInfo(server.getServerInfo());
ISelectionProvider provider = this.getSelectionProvider();
if (IDialogConstants.OK_ID == changePasswordDialog.open() && provider instanceof TreeViewer) {
TreeViewer viewer = (TreeViewer) provider;
boolean isContinue = HostUtils.processHostDisconnected(server);
if (isContinue) {
viewer.refresh(server, true);
ActionManager.getInstance().fireSelectionChanged(getSelection());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
}
}
}
Aggregations