use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class UnifyHostConfigEditor method registerCubridConfTableContextMenu.
/**
* register CubridConfTable context menu
*/
private void registerCubridConfTableContextMenu() {
cubridConfTabTableViewer.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(cubridConfTabTableViewer.getTable());
}
});
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(cubridConfTabTableViewer.getTable());
cubridConfTabTableViewer.getTable().setMenu(contextMenu);
Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
itemEditAnnotation.setText(Messages.confEditorTableMenuEditAnnotation);
itemEditAnnotation.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("all")
public void widgetSelected(SelectionEvent event) {
//seems like MenuEvent can't get the mouse click Point
//so use the point which table MouseDown event marked
Point pt = cubridConfTableClickPoint;
int selectIndex = cubridConfTabTableViewer.getTable().getSelectionIndex();
final TableItem item = cubridConfTabTableViewer.getTable().getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0; i < cubridConfTabTableViewer.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
if (i == 0) {
CommonUITool.openErrorBox(getSite().getShell(), Messages.annotationDialogOpenErrorMsg);
return;
}
IStructuredSelection selection = (IStructuredSelection) cubridConfTabTableViewer.getSelection();
HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
String serverName = cubridConfConfigListData.get(0).get(i + "");
String parentPropertyKey = valueMap.get("0");
String parentKey = " ";
Map<String, String> cubridMap = cubridConfConfigListData.get(1);
String cubridName = "";
if (cubridMap != null) {
cubridName = cubridMap.get(i + "");
}
if (selectIndex == 0) {
parentKey += serverName;
} else {
if (selectIndex == 1) {
parentKey += serverName + "->" + cubridName;
} else {
parentKey += serverName + "->" + cubridName + "->" + parentPropertyKey;
}
}
String annotationKey = Integer.toString(i) + BrokerConfPersistUtil.ANNOTATION;
CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(getSite().getShell(), parentKey, annotationKey, valueMap);
if (IDialogConstants.OK_ID == dialog.open()) {
setDirty(true);
}
}
}
}
});
final MenuItem itemAddCubridConf = new MenuItem(menu, SWT.PUSH);
itemAddCubridConf.setText(Messages.unifyHostConfigEditorAddCubridConfColumn);
itemAddCubridConf.setImage(CommonUIPlugin.getImage("icons/action/column_insert.png"));
itemAddCubridConf.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
try {
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y -
// brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
// = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
monitor.beginTask(Messages.unifyHostConfigEditorAddColumnMsg, 1);
addCubridConfColumn();
monitor.worked(1);
// horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
// brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
}
});
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
setDirty(true);
}
});
final MenuItem itemDelCubridConf = new MenuItem(menu, SWT.PUSH);
itemDelCubridConf.setText(Messages.unifyHostConfigEditorDelCubridConfColumn);
itemDelCubridConf.setImage(CommonUIPlugin.getImage("icons/action/column_delete.png"));
itemDelCubridConf.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
try {
ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
progress.setCancelable(true);
progress.run(true, true, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y -
// brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
// = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
monitor.beginTask(Messages.unifyHostConfigEditorDelColumnMsg, 1);
delCubridConfColumn();
monitor.worked(1);
// horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
// brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
}
});
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
}
});
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent event) {
//seems like MenuEvent can't get the mouse click Point
//so use the point which table MouseDown event marked
Point pt = cubridConfTableClickPoint;
// click timing
if (System.currentTimeMillis() - cubridConfTableClickPointTiming > 300) {
itemEditAnnotation.setEnabled(false);
itemDelCubridConf.setEnabled(false);
itemAddCubridConf.setEnabled(false);
return;
}
int selectIndex = cubridConfTabTableViewer.getTable().getSelectionIndex();
if (selectIndex == -1) {
itemEditAnnotation.setEnabled(false);
itemDelCubridConf.setEnabled(false);
itemAddCubridConf.setEnabled(false);
return;
}
if (selectIndex == 0) {
itemEditAnnotation.setEnabled(false);
itemDelCubridConf.setEnabled(false);
itemAddCubridConf.setEnabled(true);
return;
}
final TableItem item = cubridConfTabTableViewer.getTable().getItem(selectIndex);
if (item == null) {
return;
}
for (int i = 0; i < cubridConfTabTableViewer.getTable().getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
if (i == 0) {
itemEditAnnotation.setEnabled(false);
itemDelCubridConf.setEnabled(false);
} else {
itemEditAnnotation.setEnabled(true);
itemDelCubridConf.setEnabled(true);
}
}
}
itemAddCubridConf.setEnabled(true);
}
});
cubridConfTabTableViewer.getTable().setMenu(menu);
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class UnifyHostConfigEditor method doSave.
public void doSave(IProgressMonitor monitor) {
final HashMap<String, List<String>> failedConfMap = new HashMap<String, List<String>>();
if (editorInput.isEditCubridConf()) {
editorInput.setCubridConfPropertyCount(cubridConfTabTableViewer.getTable().getColumnCount());
}
if (editorInput.isEditCMConf()) {
editorInput.setCubridCMConfPropertyCount(cubridCMConfTabTableViewer.getTable().getColumnCount());
}
if (editorInput.isEditBrokerConf()) {
editorInput.setBrokerConfPropertyCount(brokerConfTabTableViewer.getTable().getColumnCount());
}
try {
ProgressMonitorDialog progress = new ProgressMonitorDialog(getSite().getShell());
progress.setCancelable(false);
progress.run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
monitor.beginTask(Messages.unifyHostConfigEditorSavingDataMsg, editorInput.getTaskCountValue());
if (editorInput.isEditCubridConf()) {
LinkedHashMap<String, CubridConfConfig> cubridConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridConfConfig(cubridConfConfigListData, editorInput.getCubridConfPropertyCount());
List<String> failedcubridConfServer = unifyHostConfigUtil.saveCubridConf(monitor, cubridConfMap, editorInput.getCubridServers());
if (failedcubridConfServer.size() > 0) {
failedConfMap.put("cubrid.conf", failedcubridConfServer);
}
}
if (editorInput.isEditCMConf()) {
LinkedHashMap<String, CubridCMConfConfig> cubridCMConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridCMConfConfig(cubridConfCMConfigListData, editorInput.getCubridCMConfPropertyCount());
List<String> failedcubridConfServer = unifyHostConfigUtil.saveCubridCMConf(monitor, cubridCMConfMap, editorInput.getCubridServers());
if (failedcubridConfServer.size() > 0) {
failedConfMap.put("cm.conf", failedcubridConfServer);
}
}
if (editorInput.isEditBrokerConf()) {
LinkedHashMap<String, BrokerConfig> brokerConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridBrokerConfig(cubridBrokerConfListData, editorInput.getBrokerConfPropertyCount());
List<String> failedBrokerConfServer = unifyHostConfigUtil.saveBrokerConf(monitor, brokerConfMap, editorInput.getCubridServers());
if (failedBrokerConfServer.size() > 0) {
failedConfMap.put("cubrid_broker.conf", failedBrokerConfServer);
}
}
}
});
} catch (Exception e) {
LOGGER.error("", e);
}
// }
if (failedConfMap.size() == 0) {
CommonUITool.openInformationBox(Messages.unifyHostConfigEditorSavingDataSuccessMsg);
} else {
StringBuilder sb = new StringBuilder();
for (Entry<String, List<String>> entry : failedConfMap.entrySet()) {
sb.append(entry.getKey()).append(" on ").append(entry.getValue()).append(StringUtil.NEWLINE);
}
CommonUITool.openInformationBox(Messages.bind(Messages.unifyHostConfigEditorSavingErrMsg, sb.toString()));
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class CopyDatabaseDialog method execTask.
/**
* Execute tasks
*
* @param buttonId the button id
* @param tasks the task array
* @param cancelable whether can be canceled
* @param shell the shell
*/
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
final Display display = shell.getDisplay();
isRunning = false;
try {
new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
if (monitor.isCanceled()) {
return;
}
isRunning = true;
Thread thread = new Thread() {
public void run() {
while (!monitor.isCanceled() && isRunning) {
try {
sleep(1);
} catch (InterruptedException e) {
}
}
if (monitor.isCanceled()) {
for (SocketTask t : tasks) {
if (t != null) {
t.cancel();
}
}
}
}
};
thread.start();
if (monitor.isCanceled()) {
isRunning = false;
return;
}
for (SocketTask task : tasks) {
if (task != null) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
isRunning = false;
return;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(getShell(), msg);
}
});
isRunning = false;
return;
}
}
if (monitor.isCanceled()) {
isRunning = false;
return;
}
}
if (monitor.isCanceled()) {
isRunning = false;
return;
}
if (!monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
if (buttonId > 0) {
setReturnCode(buttonId);
close();
}
}
});
}
isRunning = false;
monitor.done();
}
});
} catch (InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class LoadMonitorStatisticDataProgress method loadMonitorStatisticData.
/**
* load MonitorStatisticData list
*
* @return Catalog
*/
public void loadMonitorStatisticData() {
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
try {
new ProgressMonitorDialog(null).run(true, false, LoadMonitorStatisticDataProgress.this);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.
the class KillTransactionDialog method executeKillTrans.
/**
*
* Execute to kill transaction
*
* @param buttonId the button id
* @param tasks the task array
* @param cancelable whether it can be cancelable
* @param shell the shell
*/
public void executeKillTrans(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
final Display display = shell.getDisplay();
isRunning = false;
try {
new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
if (monitor.isCanceled()) {
return;
}
isRunning = true;
Thread thread = new Thread() {
public void run() {
while (!monitor.isCanceled() && isRunning) {
try {
sleep(1);
} catch (InterruptedException e) {
}
}
if (monitor.isCanceled()) {
for (SocketTask t : tasks) {
if (t != null) {
t.cancel();
}
}
}
}
};
thread.start();
if (monitor.isCanceled()) {
isRunning = false;
return;
}
for (SocketTask task : tasks) {
if (task != null) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
isRunning = false;
return;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(getShell(), msg);
}
});
isRunning = false;
return;
}
}
if (monitor.isCanceled()) {
isRunning = false;
return;
}
}
if (monitor.isCanceled()) {
isRunning = false;
return;
}
if (!monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
if (buttonId > 0) {
setReturnCode(buttonId);
close();
}
}
});
}
isRunning = false;
monitor.done();
}
});
} catch (InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
}
Aggregations