-
Notifications
You must be signed in to change notification settings - Fork 49
/
ExecuteVdbAction.java
120 lines (101 loc) · 3.7 KB
/
ExecuteVdbAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.runtime.ui.vdb;
import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.spi.ITeiidServerManager;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.ui.common.util.UiUtil;
import org.teiid.designer.ui.util.ErrorHandler;
import org.teiid.designer.vdb.Vdb;
import org.teiid.designer.vdb.XmiVdb;
/**
* @since 8.0
*/
public class ExecuteVdbAction extends Action {
@SuppressWarnings("javadoc")
public static final String THIS_CLASS = I18nUtil.getPropertyPrefix(ExecuteVdbAction.class);
ExecuteVdbWorker worker;
Properties designerProperties;
/**
* @since 5.0
*/
public ExecuteVdbAction() {
super();
setImageDescriptor(DqpUiPlugin.getDefault().getImageDescriptor(DqpUiConstants.Images.EXECUTE_VDB));
setToolTipText(DqpUiConstants.UTIL.getString(THIS_CLASS + "tooltip")); //$NON-NLS-1$
worker = new ExecuteVdbWorker();
}
/**
* Execute VDB
* @param properties the properties
* @since 5.0
*/
public ExecuteVdbAction(Properties properties) {
this();
designerProperties = properties;
}
@Override
public void run() {
if (!checkForConnectedServer())
return;
ExecuteVdbDialog dialog = new ExecuteVdbDialog(worker.getShell(), designerProperties);
dialog.open();
if (dialog.getReturnCode() != Window.OK)
return;
IFile vdb = dialog.getSelectedVdb();
if (vdb == null)
return;
try {
if (!isVdbSyncd(vdb) ) {
Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
String title = UTIL.getString("VdbNotSyncdDialog.title"); //$NON-NLS-1$
String msg = UTIL.getString("VdbNotSyncdDialog.msg"); //$NON-NLS-1$
if (!MessageDialog.openQuestion(shell, title, msg))
return;
}
if( !VdbErrorChecker.hasErrors(vdb, false)) {
return;
}
worker.run(vdb);
} catch (Exception ex) {
ErrorHandler.toExceptionDialog(ex);
}
}
/*
* Check that the default teiid instance is connected. Show dialog if it is not.
* @return 'true' if default teiid instance is connected, 'false' if not.
*/
private boolean checkForConnectedServer() {
ITeiidServer teiidServer = getServerManager().getDefaultServer();
if(teiidServer == null || !teiidServer.isConnected()) {
Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
String title = UTIL.getString("ActionRequiresServer.title"); //$NON-NLS-1$
String msg = UTIL.getString("ActionRequiresServer.msg"); //$NON-NLS-1$
MessageDialog.openInformation(shell,title,msg);
return false;
}
return true;
}
private boolean isVdbSyncd(IFile file) throws Exception {
Vdb vdb = new XmiVdb(file);
return vdb.isSynchronized();
}
private static ITeiidServerManager getServerManager() {
return DqpPlugin.getInstance().getServerManager();
}
}