Skip to content

Commit

Permalink
TEIIDDES-1459: Fix listener communication
Browse files Browse the repository at this point in the history
* plugin.xml
* TeiidView
 * Adds a TeiidEmptyNode as another object that will enable the
   action provider. This is in turn allows the actions to be displayed
   on the toolbar of the TeiidView

* DqpUiPlugin
 * Convenience method for opening the teiid server editor

* TeiidServerEditor
 * Registers itself with the TeiidServerManager so that any changes
   are made to the TeiidServer it represents will be reflected in the
   display UI components, eg. changing the admin password on the
   server editor.

* TeiidServer
 * Only when its parent has been started can the correct jdbc port
   be discovered so correct the port if necessary
 * Fixes incorrect vdb name when undeploying the jdbc ping vdb

* TeiidServerManager
 * Listens to ServerCore's servers and adds, removes and updates its
   collection of teiid servers as a result

* TeiidServerUtils
 * Fixes error with test model

* TeiidServerAdapterFactory
 * Better enumeration for ServerOptions
 * Makes the createTeiidServer method public and more flexible in
   what it does.
  • Loading branch information
Paul Richardson committed Sep 7, 2012
1 parent 7c3e9b7 commit 862e324
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 58 deletions.
3 changes: 3 additions & 0 deletions plugins/org.teiid.designer.dqp.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidErrorNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidEmptyNode">
</instanceof>
</or>
</enablement>
</actionProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.BundleContext;
import org.teiid.core.PluginUtil;
import org.teiid.core.util.I18nUtil;
import org.teiid.core.util.PluginUtilImpl;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.runtime.connection.IPasswordProvider;
import org.teiid.designer.runtime.preview.jobs.TeiidPreviewVdbCleanupJob;
import org.teiid.designer.runtime.ui.connection.PreviewMissingPasswordDialog;
import org.teiid.designer.runtime.ui.server.editor.TeiidServerEditor;
import org.teiid.designer.runtime.ui.server.editor.TeiidServerEditorInput;
import org.teiid.designer.ui.common.AbstractUiPlugin;
import org.teiid.designer.ui.common.actions.ActionService;
import org.teiid.designer.ui.common.util.UiUtil;
Expand Down Expand Up @@ -237,4 +242,21 @@ public void run() {
return password[0];
}
}

/**
* Open the {@link TeiidServerEditor} for the given {@link TeiidServer}
*
* @param server
*/
public static void editTeiidServer(TeiidServer server) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();

try {
TeiidServerEditorInput input = new TeiidServerEditorInput(server.getUrl());
page.openEditor(input, TeiidServerEditor.EDITOR_ID);
} catch (Exception e) {
DqpUiConstants.UTIL.log(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.runtime.ui.server.editor.TeiidServerEditor;
import org.teiid.designer.runtime.ui.server.editor.TeiidServerEditorInput;
import org.teiid.designer.runtime.ui.views.TeiidView;
import org.teiid.designer.ui.common.util.UiUtil;

Expand Down Expand Up @@ -83,7 +78,7 @@ public EditServerAction( Shell shell,
public void run() {
// if serverBeingEdited == NULL need to query user to select one in order to continue

if( this.serverBeingEdited == null ) {
if( this.serverBeingEdited == null && teiidServerManager.getServers().size() > 0) {
ServerSelectionDialog dialog = new ServerSelectionDialog(this.shell);
dialog.open();

Expand All @@ -94,16 +89,8 @@ public void run() {

if( this.serverBeingEdited == null ) return;

IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();

try {
TeiidServerEditorInput input = new TeiidServerEditorInput(serverBeingEdited.getUrl());
page.openEditor(input, TeiidServerEditor.EDITOR_ID);
} catch (Exception e) {
DqpUiConstants.UTIL.log(e);
}

DqpUiPlugin.editTeiidServer(serverBeingEdited);

// refresh viewer in Teiid View to display latest label
TeiidView teiidView = (TeiidView)UiUtil.getViewPart(DqpUiConstants.Extensions.CONNECTORS_VIEW_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.wst.server.ui.internal.ServerUIPlugin;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.ExecutionConfigurationEvent;
import org.teiid.designer.runtime.IExecutionConfigurationListener;
import org.teiid.designer.runtime.TeiidJdbcInfo;
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.ui.common.util.WidgetFactory;

/**
Expand All @@ -42,6 +46,8 @@ public class TeiidServerEditor extends EditorPart {
* Identifier of this editor
*/
public static final String EDITOR_ID = TeiidServerEditor.class.getCanonicalName();

private TeiidServerManager serverManager;

private TeiidServer teiidServer;

Expand Down Expand Up @@ -78,13 +84,27 @@ public void linkActivated(HyperlinkEvent e) {
}
};

private IExecutionConfigurationListener excutionConfigListener = new IExecutionConfigurationListener() {

@Override
public void configurationChanged(ExecutionConfigurationEvent event) {
if (teiidServer != event.getServer())
return;

refreshDisplayValues();
}
};

@Override
public void init(IEditorSite site, IEditorInput input) {
setSite(site);
setInput(input);
if (input instanceof TeiidServerEditorInput) {
TeiidServerEditorInput tsei = (TeiidServerEditorInput) input;
teiidServer = tsei.getTeiidServer();
serverManager = DqpPlugin.getInstance().getServerManager();

serverManager.addListener(excutionConfigListener);
}
}

Expand Down Expand Up @@ -255,6 +275,26 @@ public void linkActivated(HyperlinkEvent e) {
section.setClient(composite);
}

private void refreshDisplayValues() {
this.getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
customNameText.setText(teiidServer.getCustomLabel() != null ? teiidServer.getCustomLabel() : ""); //$NON-NLS-1$
hostNameText.setText(teiidServer.getHost());
jbServerNameHyperlink.setText(teiidServer.getParent() != null ? teiidServer.getParent().getName() : ""); //$NON-NLS-1$
jdbcUserNameText.setText(teiidServer.getTeiidJdbcInfo().getUsername());
jdbcPasswdText.setText(teiidServer.getTeiidJdbcInfo().getPassword());
jdbcPort.setText(teiidServer.getTeiidJdbcInfo().getPort());
}
});
}

@Override
public void dispose() {
serverManager.removeListener(excutionConfigListener);
super.dispose();
}

@Override
public void setFocus() {
if(customNameText != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
Expand All @@ -48,6 +49,7 @@
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerLifecycleListener;
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.util.ServerLifecycleAdapter;
import org.teiid.adminapi.Model;
import org.teiid.core.util.CoreStringUtil;
import org.teiid.core.util.I18nUtil;
Expand All @@ -64,6 +66,7 @@
import org.teiid.designer.runtime.connection.SourceConnectionBinding;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.runtime.ui.views.content.TeiidEmptyNode;
import org.teiid.designer.runtime.ui.views.content.TeiidFolder;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.common.util.KeyInValueHashMap;
Expand Down Expand Up @@ -169,7 +172,7 @@ public String getKey(IServer value) {

private KeyInValueHashMap<String, IServer> serverMap = new KeyInValueHashMap<String, IServer>(adapter);

private IServerLifecycleListener serversListener = new IServerLifecycleListener() {
private IServerLifecycleListener serversListener = new ServerLifecycleAdapter() {

private void refresh() {
jbossServerCombo.getDisplay().asyncExec(new Runnable() {
Expand All @@ -189,11 +192,6 @@ public void serverAdded(IServer server) {
public void serverRemoved(IServer server) {
refresh();
}

@Override
public void serverChanged(IServer server) {
// do nothing
}
};

/**
Expand Down Expand Up @@ -343,10 +341,20 @@ private void populateJBossServerCombo() {
* to the viewer
*/
private void handleServerComboSelection() {
TeiidEmptyNode emptyNode = new TeiidEmptyNode();
// populate viewer
String serverName = jbossServerCombo.getText();
IServer server = serverMap.get(serverName);
viewer.setInput(server);
if (server == null) {
viewer.setInput(emptyNode);
} else {
viewer.setInput(server);
}

// Ensures that the action provider is properly initialised in this view
IStructuredSelection selection = new StructuredSelection(emptyNode);
getNavigatorActionService().setContext(new ActionContext(selection));
getNavigatorActionService().fillActionBars(getViewSite().getActionBars());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.views.content;

import org.teiid.designer.runtime.ui.views.TeiidView;

/**
* An empty class used for setting as the input of the viewer
* in the {@link TeiidView}. Will display nothing in the viewer
* but allow all actions in the action provider to display correctly
*/
public class TeiidEmptyNode {

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public void serverChanged(ServerEvent event) {
disconnect();
notifyRefresh();
} else if (state == IServer.STATE_STARTED && TeiidServerAdapterUtil.isJBossServerConnected(event.getServer())) {

// Ask the jboss server what port we are on as it may
// still be set to the default port and this may be different
// in the jboss server.
String port = TeiidServerAdapterUtil.getJdbcPort(parentServer);
teiidJdbcInfo.setPort(port);

try {
getAdmin();
} catch (Exception ex) {
Expand Down Expand Up @@ -422,7 +429,7 @@ public IStatus testJDBCPing(String host, String port, String username, String pa
String msg = Util.getString("serverDeployUndeployProblemPingingTeiidJdbc", url); //$NON-NLS-1$
return new Status(IStatus.ERROR, PLUGIN_ID, msg, ex);
} finally {
adminApi.undeploy("ping"); //$NON-NLS-1$
adminApi.undeploy("ping-vdb.xml"); //$NON-NLS-1$

if( teiidJdbcConnection != null ) {
teiidJdbcConnection.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerLifecycleListener;
import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.util.ServerLifecycleAdapter;
import org.jboss.ide.eclipse.as.core.server.internal.v7.JBoss7Server;
import org.teiid.core.util.Base64;
import org.teiid.core.util.CoreArgCheck;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.runtime.adapter.TeiidServerAdapterFactory;
import org.teiid.designer.runtime.adapter.TeiidServerAdapterFactory.ServerOptions;
import org.teiid.designer.runtime.connection.IPasswordProvider;
import org.teiid.designer.runtime.preview.PreviewManager;
import org.teiid.net.TeiidURL;
Expand Down Expand Up @@ -190,6 +194,48 @@ private enum RuntimeState {
* The status of this manager.
*/
private RuntimeState state = RuntimeState.INVALID;

/**
* Listener for removing teiid servers if there parent server is removed
*/
private IServerLifecycleListener serversListener = new ServerLifecycleAdapter() {

@Override
public void serverAdded(IServer server) {
TeiidServerAdapterFactory factory = new TeiidServerAdapterFactory();
factory.createTeiidServer(server, TeiidServerManager.this, ServerOptions.ADD_TO_REGISTRY);
};

@Override
public void serverChanged(IServer server) {
for (TeiidServer teiidServer : getServers()) {
if (server.equals(teiidServer.getParent())) {
TeiidServerAdapterFactory factory = new TeiidServerAdapterFactory();
TeiidServer newTeiidServer = factory.createTeiidServer(server, TeiidServerManager.this);

// Cannot use updateServer as it replaces rather than modified the existing server
// and references in editor will thus hang on to the old defunct version
teiidServer.getTeiidAdminInfo().setAll(newTeiidServer.getTeiidAdminInfo());
teiidServer.getTeiidJdbcInfo().setAll(newTeiidServer.getTeiidJdbcInfo());
teiidServer.notifyRefresh();

return;
}
}
};

@Override
public void serverRemoved(IServer server) {

// Tidy up the server manager by removing the related teiid server
for (TeiidServer teiidServer : getServers()) {
if (server.equals(teiidServer.getParent())) {
removeServer(teiidServer);
break;
}
}
}
};

// ===========================================================================================================================
// Constructors
Expand Down Expand Up @@ -220,12 +266,24 @@ public TeiidServerManager( String stateLocationPath, IPasswordProvider passwordP

this.previewManager = tempPreviewManager;
this.state = RuntimeState.STARTED;

ServerCore.addServerLifecycleListener(serversListener);
}

// ===========================================================================================================================
// Methods
// ===========================================================================================================================

/**
* Get the {@link IServerLifecycleListener} referenced by this
* manager
*
* @return {@link IServerLifecycleListener}
*/
public IServerLifecycleListener getServerLifeCycleListener() {
return serversListener;
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -712,6 +770,9 @@ public void setDefaultServer( TeiidServer teiidServer ) {
* @param monitor the progress monitor (may be <code>null</code>)
*/
public void shutdown( IProgressMonitor monitor ) throws Exception {

ServerCore.removeServerLifecycleListener(serversListener);

// return if already being shutdown
if ((this.state == RuntimeState.SHUTTING_DOWN) || (this.state == RuntimeState.SHUTDOWN)) return;

Expand Down

0 comments on commit 862e324

Please sign in to comment.