Skip to content

Commit

Permalink
TEIIDDES-1694 Improves options for setting the default server
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed May 2, 2013
1 parent 4548e42 commit ee19348
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ public interface AdvisorUiConstants {
String[] ASPECT_TEIID_SERVER = {
COMMAND_IDS.NEW_TEIID_SERVER,
COMMAND_IDS.EDIT_TEIID_SERVER,
// COMMAND_IDS.CREATE_DATA_SOURCE,
// COMMAND_IDS.DEPLOY_VDB,
// COMMAND_IDS.EXECUTE_VDB,
COMMAND_IDS.SET_DEFAULT_TEIID_SERVER
};

String[] ASPECT_TEST = {
Expand Down
7 changes: 6 additions & 1 deletion plugins/org.teiid.designer.dqp.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ teiidView.navigatorContent.name = Teiid View Navigator Configuration

newJbossTeiidServerCommand.label = New JBoss Teiid Server
newTeiidServerAction.description = Show wizard for configuring new JBoss Teiid Server
teiidServerEditor.title = Teiid Server
teiidServerEditor.title = Teiid Server

setDefaultServerCommand.label = Change Teiid Server
setDefaultServerAction.description = Show dialog for changing Teiid Server
editServerCommand.label = Edit Teiid Server
editServerAction.description = Show dialog for editing Teiid Server
12 changes: 12 additions & 0 deletions plugins/org.teiid.designer.dqp.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@
id="org.teiid.designer.dqp.ui.newServerAction"
name="%newJbossTeiidServerCommand.label">
</command>
<command
defaultHandler="org.teiid.designer.runtime.ui.server.SetDefaultServerAction"
description="%setDefaultServerAction.description"
id="org.teiid.designer.dqp.ui.setDefaultServerAction"
name="%setDefaultServerCommand.label">
</command>
<command
defaultHandler="org.teiid.designer.runtime.ui.server.EditServerAction"
description="%editServerAction.description"
id="org.teiid.designer.dqp.ui.editServerAction"
name="%editServerCommand.label">
</command>
</extension>
<extension point="org.eclipse.ui.editors">
<editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
package org.teiid.designer.runtime.ui.server;

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

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.ui.DqpUiPlugin;

Expand All @@ -22,44 +26,48 @@
*
* @since 8.0
*/
public final class EditServerAction extends BaseSelectionListenerAction {
public final class EditServerAction extends BaseSelectionListenerAction implements IHandler {

// ===========================================================================================================================
// Fields
// ===========================================================================================================================

/**
* The selected server being edited.
* Flag determines if default is being edited, or supplied
*/
private ITeiidServer serverBeingEdited;
ITeiidServer serverBeingEdited = null;
private boolean editDefault = false;

/**
* The server manager used to create and edit servers.
*/
private final TeiidServerManager teiidServerManager;

/**
* The shell used to display the dialog that edits and creates servers.
*/
private final Shell shell;
private Shell shell;

// ===========================================================================================================================
// Constructors
// ===========================================================================================================================

/**
* @param shell the parent shell used to display the dialog
* @param teiidServerManager the server manager to use when creating and editing servers
* Default Constructor
*/
public EditServerAction( Shell shell,
TeiidServerManager teiidServerManager ) {
public EditServerAction( ) {
super(UTIL.getString("editServerActionText")); //$NON-NLS-1$
setToolTipText(UTIL.getString("editServerActionToolTip")); //$NON-NLS-1$
setImageDescriptor(DqpUiPlugin.getDefault().getImageDescriptor(DqpUiPlugin.Images.EDIT_SERVER_ICON));
setEnabled(true);
this.shell = getShell();
this.editDefault = true;
}

/**
* @param shell the parent shell used to display the dialog
* @param editDefault 'true' will edit the current default, 'false' will show a chooser dialog
*/
public EditServerAction( Shell shell, boolean editDefault ) {
this();
setEnabled(false);

this.shell = shell;
this.teiidServerManager = teiidServerManager;
this.editDefault = editDefault;
}

// ===========================================================================================================================
Expand All @@ -73,22 +81,30 @@ public EditServerAction( Shell shell,
*/
@Override
public void run() {
// if serverBeingEdited == NULL need to query user to select one in order to continue

if( this.serverBeingEdited == null) {
this.serverBeingEdited = RuntimeAssistant.selectServer(shell);
// Edit the Default server
if(this.editDefault) {
serverBeingEdited = ModelerCore.getDefaultServer();
// Choose Server to Edit
} else {
serverBeingEdited = RuntimeAssistant.selectServer(this.shell,false);
}

if( this.serverBeingEdited == null ) {
if(RuntimeAssistant.selectServerWasCancelled()) return;

if( serverBeingEdited == null ) {
String title = UTIL.getString("noServerAvailableTitle"); //$NON-NLS-1$
String message = UTIL.getString("noServerAvailableMessage"); //$NON-NLS-1$
MessageDialog.openError(shell, title, message);
MessageDialog.openError(this.shell, title, message);
return;
}

DqpUiPlugin.editTeiidServer(serverBeingEdited);
}

private static Shell getShell() {
return DqpUiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();
}

/**
* {@inheritDoc}
*
Expand All @@ -115,4 +131,25 @@ protected boolean updateSelection( IStructuredSelection selection ) {
return false;
}

@Override
public void addHandlerListener(IHandlerListener handlerListener) {
// Not required
}

@Override
public void dispose() {
// Not required
}

@Override
public Object execute(ExecutionEvent event) {
run();
return null;
}

@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
// Not required
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class RuntimeAssistant {
* The I18n properties prefix key used by this class.
*/
private static final String PREFIX = I18nUtil.getPropertyPrefix(RuntimeAssistant.class);
private static boolean selectServerCancelled = false;

/**
* If the preview preference is disabled or a Teiid server does not exist, a dialog is shown asking the user if they want to
Expand Down Expand Up @@ -158,7 +159,7 @@ public static void runNewServerAction( Shell shell ) {
* @param shell the shell used to run the new server wizard
*/
public static void runEditServerAction( Shell shell ) {
EditServerAction action = new EditServerAction(shell, getServerManager());
EditServerAction action = new EditServerAction(shell, false);
action.run();
}

Expand Down Expand Up @@ -229,25 +230,46 @@ private RuntimeAssistant() {
* Can display a dialog, allowing the user to select a server should there
* be more than one or return the single server in the event of only one.
*
* @param shell
* @param shell the shell
* @param includeNoDefaultOption 'true' includes the 'No Default' option, 'false' does not.
*
* @return a selected {@link ITeiidServer}
*/
public static ITeiidServer selectServer(Shell shell) {
public static ITeiidServer selectServer(Shell shell, boolean includeNoDefaultOption) {
ITeiidServer selectedServer = null;

selectServerCancelled = false;

if (getServerManager().getServers().size() == 1) {
selectedServer = getServerManager().getServers().iterator().next();
} else if (getServerManager().getServers().size() > 1) {
ServerSelectionDialog dialog = new ServerSelectionDialog(shell);
ServerSelectionDialog dialog = new ServerSelectionDialog(shell,includeNoDefaultOption);
dialog.open();

if (dialog.getReturnCode() == Window.OK) {
selectedServer = dialog.getServer();
} else {
selectServerCancelled = true;
}
}

return selectedServer;
}

/**
* Determine if the last server selection was cancelled.
* @return 'true' if the selection dialog was cancelled, 'false' if not.
*/
public static boolean selectServerWasCancelled() {
return selectServerCancelled;
}

/**
* Determine if at least one available server
* @return 'true' if at least one server is available, 'false' if not.
*/
public static boolean hasAvailableServers() {
if(getServerManager().getServers().size()>0) return true;
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,24 @@ public class ServerSelectionDialog extends TitleAreaDialog implements
DqpUiConstants, IChangeListener {

private static final String PREFIX = I18nUtil.getPropertyPrefix(ServerSelectionDialog.class);
private static final String NO_DEFAULT = "No Default"; //$NON-NLS-1$

private ITeiidServer selectedServer;

private Combo serversCombo;
private boolean includeNoDefaultOption = false;

private Map<String, ITeiidServer> serverMap = new HashMap<String, ITeiidServer>();

/**
* @since 5.5.3
* Constructor
* @param parentShell the parent shell
* @param includeNoDefaultOption 'true' includes a 'No Default' option in addition to available servers
*/
public ServerSelectionDialog(Shell parentShell) {
public ServerSelectionDialog(Shell parentShell, boolean includeNoDefaultOption) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
this.includeNoDefaultOption = includeNoDefaultOption;
}

/**
Expand All @@ -67,7 +72,7 @@ protected void configureShell(Shell shell) {
@Override
protected Control createButtonBar(Composite parent) {
Control buttonBar = super.createButtonBar(parent);
getButton(OK).setEnabled(false);
getButton(OK).setEnabled(true);

// set the first selection so that initial validation state is set
// (doing it here since the selection handler uses OK
Expand Down Expand Up @@ -117,15 +122,45 @@ public void widgetSelected(SelectionEvent ev) {
}
});
Collection<ITeiidServer> teiidServers = DqpPlugin.getInstance().getServerManager().getServers();
ITeiidServer currentDefault = DqpPlugin.getInstance().getServerManager().getDefaultServer();
String currentServerStr = null;
if(currentDefault==null) {
currentServerStr = NO_DEFAULT;
} else {
currentServerStr = currentDefault.toString();
}

// Add NO_DEFAULT option if desired
if(this.includeNoDefaultOption) serverMap.put(NO_DEFAULT, null);

// Add remaining servers from DQP Plugin
for( ITeiidServer teiidServer : teiidServers ) {
serverMap.put(teiidServer.toString(), teiidServer);
}

WidgetUtil.setComboItems(serversCombo, serverMap.keySet(), null, true);
// Set initial selection
boolean setInitial = false;
for(int i=0; i<serversCombo.getItemCount(); i++) {
String serverName = serversCombo.getItem(i);
if(serverName!=null && serverName.equalsIgnoreCase(currentServerStr)) {
serversCombo.select(i);
selectedServer = serverMap.get(serverName);
setInitial = true;
break;
}
}
// If initial selection was not found, set to first item.
if(!setInitial && serversCombo.getItemCount()>0) serversCombo.select(0);
}

return panel;
}

/**
* Get the selected server
* @return the selected server
*/
public ITeiidServer getServer() {
return this.selectedServer;
}
Expand All @@ -140,20 +175,18 @@ public void stateChanged(IChangeNotifier theSource) {
}

private void updateState() {

if (this.selectedServer == null ) {
// selectedServer == null is a valid choice (No Default)
getButton(OK).setEnabled(true);

if(!this.includeNoDefaultOption && this.serversCombo.getItemCount()==0) {
getButton(OK).setEnabled(false);
if( this.serversCombo.getItemCount() == 0 ) {
setErrorMessage(UTIL.getString(PREFIX + "noServersExistMessage")); //$NON-NLS-1$
} else {
setErrorMessage(UTIL.getString(PREFIX + "noServerSelectedMessage")); //$NON-NLS-1$
}


} else {
getButton(OK).setEnabled(true);
setErrorMessage(UTIL.getString(PREFIX + "noServersExistMessage")); //$NON-NLS-1$
return;
}

if(this.includeNoDefaultOption && this.serversCombo.getItemCount()==1) {
setErrorMessage(null);
setMessage(UTIL.getString(PREFIX + "okMsg")); //$NON-NLS-1$
setMessage(UTIL.getString(PREFIX + "noServersExistMessage")); //$NON-NLS-1$
}
}
}
Loading

0 comments on commit ee19348

Please sign in to comment.