Skip to content

Commit

Permalink
Displays the teiid server content on the status bar
Browse files Browse the repository at this point in the history
* Replaces the manual updateStatusLine method in TeiidView
  with the universal method of having the label provider
  implement IDescriptionProvider
  • Loading branch information
Paul Richardson committed Nov 10, 2012
1 parent ca73bd2 commit 3c15915
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ VdbDefinitionLabelProvider.none.ReadOnly = (no connector defined)
duplicateNameMsg=A connector with the name "{0}" already exists.
nameIsValidMsg=Name is valid

########## TeiidServerLabelProvider #############
TeiidDataNode.activeVdb=ACTIVE
TeiidDataNode.inactiveVdb=INACTIVE

########## TeiidView ##########
TeiidView.openAction.text=Open
TeiidView.title.text=Teiid
Expand Down Expand Up @@ -583,6 +579,8 @@ TeiidServerContainerNode.ServerContentLabelNotConnected=Not Connected
DataSourcesFolder.label = Data Sources
VdbsFolder.label = VDBs
TranslatorsFolder.label = Translators
TeiidDataNode.activeVdb=ACTIVE
TeiidDataNode.inactiveVdb=INACTIVE

PasswordProvider.missingPasswordMessage=The data source for model "{0}" requires a password. \nThe referenced connection profile is "{1}."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.jcip.annotations.GuardedBy;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IDecoration;
Expand All @@ -19,6 +21,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.IDescriptionProvider;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.TeiidServerManager;
Expand All @@ -37,13 +40,18 @@
* @since 8.0
*/

public class TeiidServerLabelProvider extends ColumnLabelProvider implements ILightweightLabelDecorator {
public class TeiidServerLabelProvider extends ColumnLabelProvider implements ILightweightLabelDecorator, IDescriptionProvider {

/**
* If a server connection cannot be established, wait this amount of time before trying again.
*/
private static final long RETRY_DURATION = 2000;

/**
* Pattern for use with modifying text for the description
*/
private static Pattern pattern = Pattern.compile("[\\\n\\\t]+"); //$NON-NLS-1$

private TeiidServerManager serverMgr;

/**
Expand Down Expand Up @@ -206,4 +214,12 @@ private synchronized boolean isOkToConnect(TeiidServer teiidServer) {
// OK to try and connect
return true;
}

@Override
public String getDescription(Object element) {
String text = element.toString();

Matcher matcher = pattern.matcher(text);
return matcher.replaceAll(" "); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
Expand Down Expand Up @@ -41,7 +39,6 @@
import org.eclipse.wst.server.core.IServerLifecycleListener;
import org.eclipse.wst.server.core.util.ServerLifecycleAdapter;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.TeiidDataSource;
import org.teiid.designer.runtime.TeiidServerManager;
Expand Down Expand Up @@ -279,13 +276,6 @@ public void widgetDefaultSelected(SelectionEvent e) {

viewer.setSorter(new NameSorter());

viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged( SelectionChangedEvent event ) {
handleSelectionChanged(event);
}
});

DqpPlugin.getInstance().getServersProvider().addServerLifecycleListener(serversListener);

// Populate the jboss server combo box which
Expand Down Expand Up @@ -364,10 +354,6 @@ TeiidServerManager getServerManager() {
return DqpPlugin.getInstance().getServerManager();
}

void handleSelectionChanged( SelectionChangedEvent event ) {
updateStatusLine((IStructuredSelection)event.getSelection());
}

/**
* {@inheritDoc}
*
Expand All @@ -394,22 +380,6 @@ public void setFocus() {
viewer.getControl().setFocus();
}

/**
* Updates Eclipse's Status line based on current selection in Teiid View
*
* @param selection the current viewer selection (never <code>null</code>)
*/
private void updateStatusLine( IStructuredSelection selection ) {
// If no selection or mutli-selection
String msg = StringUtilities.EMPTY_STRING;

if (selection.size() == 1) {
Object selectedObject = selection.getFirstElement();
msg = selectedObject.toString();
}
getViewSite().getActionBars().getStatusLineManager().setMessage(msg);
}

class NameSorter extends ViewerSorter {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
package org.teiid.designer.runtime.ui.views;

import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.ui.navigator.IDescriptionProvider;
import org.teiid.designer.runtime.ui.DqpUiPlugin;

/**
* @since 8.0
*/
public class TeiidViewDecoratingLabelProvider extends DecoratingLabelProvider {
public class TeiidViewDecoratingLabelProvider extends DecoratingLabelProvider implements IDescriptionProvider {

/**
* Create a new instance
*/
public TeiidViewDecoratingLabelProvider() {
super(new TeiidServerLabelProvider(), DqpUiPlugin.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator());
}

@Override
public String getDescription(Object element) {
TeiidServerLabelProvider labelDecorator = (TeiidServerLabelProvider) getLabelProvider();
return labelDecorator.getDescription(element);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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.TeiidServerLabelProvider;

/**
* @param <V>
Expand All @@ -29,13 +28,11 @@ public class TeiidDataNode<V> implements ITeiidContentNode<AbstractTeiidFolder>
/**
* Prefix for language NLS properties
*/
private static final String PREFIX = I18nUtil.getPropertyPrefix(TeiidServerLabelProvider.class);
private static final String PREFIX = I18nUtil.getPropertyPrefix(TeiidDataNode.class);

private static final String ACTIVE_VDB = DqpUiPlugin.UTIL.getString(PREFIX + "activeVdb"); //$NON-NLS-1$
private static final String ACTIVE_VDB = DqpUiConstants.UTIL.getString(PREFIX + "activeVdb"); //$NON-NLS-1$

private static final String INACTIVE_VDB = DqpUiPlugin.UTIL.getString(PREFIX + "inactiveVdb"); //$NON-NLS-1$

private static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
private static final String INACTIVE_VDB = DqpUiConstants.UTIL.getString(PREFIX + "inactiveVdb"); //$NON-NLS-1$

private AbstractTeiidFolder parentNode;
private V value;
Expand Down Expand Up @@ -179,7 +176,7 @@ public Image getImage() {
}

/**
* @return
* @return real value of this data node
*/
public V getValue() {
return value;
Expand Down

0 comments on commit 3c15915

Please sign in to comment.