Skip to content

Commit

Permalink
Merge pull request #147 from mdrillin/TEIIDDES-1680
Browse files Browse the repository at this point in the history
TEIIDDES-1680, 1688
  • Loading branch information
blafond committed May 1, 2013
2 parents 890f0d3 + a43809b commit befb0fb
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.common.util.UiUtil;
import org.teiid.designer.vdb.Vdb;
import org.teiid.designer.vdb.Vdb;


/**
Expand All @@ -67,7 +66,7 @@ public DeployVdbAction() {
/**
* Create a new instance with given properties
*
* @param properties
* @param properties the properties
*/
public DeployVdbAction(Properties properties) {
super();
Expand Down Expand Up @@ -122,8 +121,11 @@ public boolean isApplicable( ISelection selection ) {
*/
@Override
public void run() {
ITeiidServer teiidServer = getServerManager().getDefaultServer();
// Make sure default server is connected
if(!checkForConnectedServer()) return;

ITeiidServer teiidServer = getServerManager().getDefaultServer();

for (IFile nextVDB : this.selectedVDBs) {
boolean doDeploy = VdbRequiresSaveChecker.insureOpenVdbSaved(nextVDB);
if (doDeploy) {
Expand All @@ -136,6 +138,11 @@ public void run() {
}
} catch (Exception ex) {
DqpPlugin.Util.log(ex);
Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
String vdbName = nextVDB.getFullPath().removeFileExtension().lastSegment();
String title = UTIL.getString(I18N_PREFIX + "problemDeployingVdbDataSource.title", vdbName, teiidServer); //$NON-NLS-1$
String message = UTIL.getString(I18N_PREFIX + "problemDeployingVdbDataSource.msg", vdbName, teiidServer); //$NON-NLS-1$
ErrorDialog.openError(shell, title, null, new Status(IStatus.ERROR, PLUGIN_ID, message, ex));
}
}
}
Expand All @@ -145,6 +152,9 @@ public void run() {
* Ask the user to select the vdb and deploy it
*/
public void queryUserAndRun() {
// Make sure default server is connected
if(!checkForConnectedServer()) return;

ITeiidServer teiidServer = getServerManager().getDefaultServer();

DeployVdbDialog dialog = new DeployVdbDialog(DqpUiPlugin.getDefault().getCurrentWorkbenchWindow().getShell(), designerProperties);
Expand Down Expand Up @@ -202,6 +212,22 @@ public void selectionChanged( IWorkbenchPart part,
}
}

/*
* Check that the default server is connected. Show dialog if it is not.
* @return 'true' if default server is connected, 'false' if not.
*/
private boolean checkForConnectedServer() {
ITeiidServer teiidServer = getServerManager().getDefaultServer();
if(!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 static TeiidServerManager getServerManager() {
return DqpPlugin.getInstance().getServerManager();
}
Expand All @@ -218,9 +244,9 @@ public static void deployVdb( ITeiidServer teiidServer,
/**
* Deploy the given vdb to the given teiid server
*
* @param teiidServer
* @param vdbOrVdbFile
* @param doCreateDataSource
* @param teiidServer the Teiid Server instance
* @param vdbOrVdbFile the VDB
* @param doCreateDataSource 'true' to create corresponding datasource, 'false' if not.
*/
public static void deployVdb(ITeiidServer teiidServer, final Object vdbOrVdbFile, final boolean doCreateDataSource) {
Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
Expand All @@ -237,6 +263,13 @@ public static void deployVdb(ITeiidServer teiidServer, final Object vdbOrVdbFile

Vdb vdb = ((vdbOrVdbFile instanceof IFile) ? new Vdb(
(IFile) vdbOrVdbFile, null) : (Vdb) vdbOrVdbFile);

if(!vdb.isSynchronized()) {
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;
}

final VdbDeployer deployer = new VdbDeployer(shell, vdb, teiidServer, doCreateDataSource);
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
*/
package org.teiid.designer.runtime.ui.actions;

import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPart;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
Expand All @@ -21,6 +27,8 @@
import org.teiid.designer.runtime.ui.vdb.VdbConstants;
import org.teiid.designer.ui.actions.SortableSelectionAction;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.common.util.UiUtil;
import org.teiid.designer.vdb.Vdb;


/**
Expand All @@ -37,6 +45,9 @@ public class ExecuteVDBAction extends SortableSelectionAction implements VdbCons

static ExecuteVdbWorker worker;

/**
* Execute VDB constructor
*/
public ExecuteVDBAction() {
super();
setImageDescriptor(DqpUiPlugin.getDefault().getImageDescriptor(DqpUiConstants.Images.EXECUTE_VDB));
Expand All @@ -56,8 +67,8 @@ public int compareTo( Object o ) {
}

/**
* @param selection
* @return
* @param selection the selection
* @return 'true' if applicable selection, 'false' if not
*/
@Override
public boolean isApplicable( ISelection selection ) {
Expand All @@ -82,8 +93,17 @@ public boolean isApplicable( ISelection selection ) {
*/
@Override
public void run() {
if(!checkForConnectedServer()) return;

IFile vdb = selectedVDB;

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 (vdb == null) {
ExecuteVdbDialog dialog = new ExecuteVdbDialog(worker.getShell(), null);

Expand All @@ -99,13 +119,43 @@ public void run() {
}
}

/*
* Check that the default server is connected. Show dialog if it is not.
* @return 'true' if default server is connected, 'false' if not.
*/
private boolean checkForConnectedServer() {
ITeiidServer teiidServer = getServerManager().getDefaultServer();
if(!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) {
Vdb vdb = new Vdb(file, null);
return vdb.isSynchronized();
}

/**
* Execute the VDB
* @param teiidServer the TeiidServer instance
* @param vdbName the VDB
* @throws Exception exception
*/
public static void executeVdb( ITeiidServer teiidServer, String vdbName ) throws Exception {
if( worker == null ) {
worker = new ExecuteVdbWorker();
}
worker.processForDTP(teiidServer, vdbName);
}

private static TeiidServerManager getServerManager() {
return DqpPlugin.getInstance().getServerManager();
}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ DeployVdbAction.problemDeployingVdbDataSource.msg = There was a problem deployin
DeployVdbAction.selectionIsNotAVdb = <Selection is not a VDB!>
DeployVdbAction.noTeiidInstanceMsg = In order to deploy a VDB, a Teiid instance must exist. Would you like to create a Teiid instance so that you can deploy a VDB?

ActionRequiresServer.title = Server is not connected
ActionRequiresServer.msg = This action requires a running server - please connect and retry.
VdbNotSyncdDialog.title = VDB is not Synchronized
VdbNotSyncdDialog.msg = The VDB is not Synchronized with the workspace. Do you wish to continue?

VdbRequiresSaveChecker.unsavedVdb.title=Save VDB
VdbRequiresSaveChecker.unsavedVdb.message=The {0} VDB has been modified and must be saved prior to deployment.\n\nSelect OK to save and continue or Cancel?
#########################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@
*/
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.TeiidServerManager;
import org.teiid.designer.runtime.spi.ITeiidServer;
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.vdb.Vdb;


/**
* @since 8.0
*/
public class ExecuteVdbAction extends Action {
@SuppressWarnings("javadoc")
public static final String THIS_CLASS = I18nUtil.getPropertyPrefix(ExecuteVdbAction.class);

ExecuteVdbWorker worker;
Expand All @@ -38,6 +48,8 @@ public ExecuteVdbAction() {
}

/**
* Execute VDB
* @param properties the properties
* @since 5.0
*/
public ExecuteVdbAction(Properties properties) {
Expand All @@ -47,16 +59,51 @@ public ExecuteVdbAction(Properties properties) {

@Override
public void run() {
if(!checkForConnectedServer()) return;

ExecuteVdbDialog dialog = new ExecuteVdbDialog(worker.getShell(), designerProperties);
ExecuteVdbDialog dialog = new ExecuteVdbDialog(worker.getShell(), designerProperties);

dialog.open();

if (dialog.getReturnCode() == Window.OK) {
IFile vdb = dialog.getSelectedVdb();
if (vdb != null) {

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;
}

worker.run(vdb);
}
}
}

/*
* Check that the default server is connected. Show dialog if it is not.
* @return 'true' if default server is connected, 'false' if not.
*/
private boolean checkForConnectedServer() {
ITeiidServer teiidServer = getServerManager().getDefaultServer();
if(!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) {
Vdb vdb = new Vdb(file, null);
return vdb.isSynchronized();
}

private static TeiidServerManager getServerManager() {
return DqpPlugin.getInstance().getServerManager();
}

}

0 comments on commit befb0fb

Please sign in to comment.