Skip to content

Commit

Permalink
Merge pull request #269 from mdrillin/TEIIDDES-1966
Browse files Browse the repository at this point in the history
TEIIDDES-1966 Resolves several issues with VDB Editor multi-source binding panel
  • Loading branch information
blafond committed Dec 3, 2013
2 parents a0b0376 + e4c68bf commit ce89134
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
Expand Down Expand Up @@ -170,15 +171,13 @@ public void documentChanged( final DocumentEvent event ) {
bindingsTab.setToolTipText(Messages.modelDetailsPanel_sourceBindingDefinitionTooltip);

Composite sourceBindingsGroup = new Composite(tabFolder, SWT.NONE);
sourceBindingsGroup.setLayout(new GridLayout(2, false));
sourceBindingsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
sourceBindingsGroup.setLayout(new GridLayout(1, false));
sourceBindingsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
bindingsTab.setControl(sourceBindingsGroup);

SOURCE_BINDING_PANEL : {

// 2 columns
// Options Panel at top that spans both columns
Composite subPanel_1 = WidgetFactory.createPanel(sourceBindingsGroup, SWT.NONE, GridData.FILL_BOTH, 2, 4);
Composite subPanel_1 = WidgetFactory.createPanel(sourceBindingsGroup, SWT.NONE, GridData.FILL_HORIZONTAL, 1, 4);
subPanel_1.setLayout(new GridLayout(4, false));
// Options panel contains: multi-source check-box, add column checkbox and source name alias label + text entry box
multiSourceCB = WidgetFactory.createButton(subPanel_1, Messages.modelDetailsPanel_multiSourceLabel, SWT.NONE, 1, SWT.CHECK);
Expand Down Expand Up @@ -229,16 +228,20 @@ public void modifyText(ModifyEvent e) {
}
});

// Vertical Buttons panel for ADD and DELETE buttons
Composite leftToolbarPanel = new Composite(sourceBindingsGroup, SWT.NONE);
Composite lowerPanel = WidgetFactory.createPanel(sourceBindingsGroup, SWT.NONE, GridData.FILL_BOTH, 2, 1);
lowerPanel.setLayout(new GridLayout(2, false));
GridData gridData = new GridData(GridData.FILL_BOTH | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
lowerPanel.setLayoutData(gridData);

// Vertical Buttons panel for ADD and DELETE buttons
Composite leftToolbarPanel = WidgetFactory.createPanel(lowerPanel, SWT.NONE, GridData.FILL_VERTICAL);
GridLayout tbGL = new GridLayout();
tbGL.marginHeight = 0;
tbGL.marginWidth = 0;
tbGL.verticalSpacing = 2;
leftToolbarPanel.setLayout(tbGL);
GridData ltpGD = new GridData(GridData.FILL_VERTICAL);
ltpGD.heightHint = 100;
leftToolbarPanel.setLayoutData(ltpGD);

addButton = new Button(leftToolbarPanel, SWT.PUSH);
addButton.setText(UILabelUtil.getLabel(UiLabelConstants.LABEL_IDS.ADD));
Expand All @@ -250,8 +253,12 @@ public void modifyText(ModifyEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
int numSources = selectedVdbModelEntry.getSourceInfo().getSources().size();
String newName = "Name_" + numSources; //$NON-NLS-1$
selectedVdbModelEntry.getSourceInfo().add(newName, "JNDI_NAME", "TRANSLATOR_NAME"); //$NON-NLS-1$ //$NON-NLS-2$
boolean added = false;
while(!added) {
String newName = "Name_" + numSources; //$NON-NLS-1$
added = selectedVdbModelEntry.getSourceInfo().add(newName, "JNDI_NAME", "TRANSLATOR_NAME"); //$NON-NLS-1$ //$NON-NLS-2$
if(!added) numSources++;
}
refreshModelDetails();
}

Expand All @@ -278,17 +285,20 @@ public void widgetSelected(SelectionEvent e) {
});
// Table containing Source binding NAME, TRANSLATOR NAME, JNDI NAME
BINDING_TABLE : {
Table table = new Table(sourceBindingsGroup, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
table.setHeaderVisible(true);
table.setLinesVisible(true);
// Create Table Viewer
int tableStyle = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
bindingsViewer = new TableViewer(lowerPanel, tableStyle);

Table table = bindingsViewer.getTable();
table.setLayout(new TableLayout());
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
//gd.heightHint = 80;
table.setLayoutData(gd);

bindingsViewer = new TableViewer(table);
bindingsViewer.getControl().setLayoutData(gd);

final GridData tblGD = new GridData(GridData.FILL_BOTH);
tblGD.grabExcessHorizontalSpace = true;
tblGD.grabExcessVerticalSpace = true;
table.setLayoutData(tblGD);
table.setHeaderVisible(true);
table.setLinesVisible(true);

// create columns
TableViewerColumn column = new TableViewerColumn(bindingsViewer, SWT.LEFT);
column.getColumn().setText(Messages.modelDetailsPanel_sourceNameLabel + " "); //$NON-NLS-1$
Expand Down Expand Up @@ -377,7 +387,7 @@ public void refreshModelDetails() {
addColumnCB.setEnabled(enable);
columnAliasText.setEnabled(enable);
addButton.setEnabled(enable);
deleteButton.setEnabled(selectedVdbModelEntry.getSourceInfo().getSourceCount() > 1);
deleteButton.setEnabled(selectedVdbModelEntry.getSourceInfo().getSourceCount() > 1 && !bindingsViewer.getSelection().isEmpty());
columnAliaslabel.setEnabled(enable);
if( enable ) {
columnAliasText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
Expand Down Expand Up @@ -496,7 +506,11 @@ protected void setElementValue( Object element,
}

((VdbSource)element).setTranslatorName(newValue);

refreshModelDetails();

// cause a selection event to be fired so that actions can set their enablement
bindingsViewer.setSelection(new StructuredSelection(element));
}
}

Expand Down Expand Up @@ -567,7 +581,11 @@ protected void setElementValue( Object element,
newValue = ""; //$NON-NLS-1$
}
((VdbSource)element).setJndiName(newValue);

refreshModelDetails();

// cause a selection event to be fired so that actions can set their enablement
bindingsViewer.setSelection(new StructuredSelection(element));
}
}

Expand Down Expand Up @@ -630,11 +648,39 @@ protected void setValue(Object element, Object value) {
String oldValue = ((VdbSource)element).getName();
String newValue = (String)value;
if( newValue != null && newValue.length() > 0 && !newValue.equalsIgnoreCase(oldValue)) {
((VdbSource)element).setName(newValue);
// Ensure the name is unique
String newName = ensureUniqueName(newValue, (VdbSource)element);

((VdbSource)element).setName(newName);
refreshModelDetails();

// cause a selection event to be fired so that actions can set their enablement
bindingsViewer.setSelection(new StructuredSelection(element));
}
}
}

/*
* Cannot have duplicate names. If user tries duplicate, add a suffix
*/
private String ensureUniqueName(String name, VdbSource currentSource) {
String uniqueName = name;
List<String> otherSourceNames = new ArrayList<String>();
for( VdbSource vdbSource : selectedVdbModelEntry.getSourceInfo().getSources() ) {
if(!vdbSource.equals(currentSource)) {
otherSourceNames.add(vdbSource.getName().toLowerCase());
}
}
boolean isUnique = false;
int i = 1; //Suffix added to make unique
while(!isUnique) {
isUnique = !otherSourceNames.contains(uniqueName.toLowerCase());
if(!isUnique) {
uniqueName += i;
}
}
return uniqueName;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
*/
package org.teiid.designer.vdb;

import static org.teiid.designer.vdb.Vdb.Event.MODEL_TRANSLATOR;
import static org.teiid.designer.vdb.Vdb.Event.MODEL_JNDI_NAME;
import static org.teiid.designer.vdb.Vdb.Event.MODEL_SOURCE_NAME;
import static org.teiid.designer.vdb.Vdb.Event.MODEL_TRANSLATOR;

import org.teiid.core.designer.util.CoreStringUtil;
import org.teiid.designer.core.util.StringUtilities;

/**
Expand Down Expand Up @@ -109,4 +110,24 @@ public String toString() {

return text.toString();
}

/**
* {@inheritDoc}
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals( Object object ) {
if (this == object) {
return true;
}

if ((object == null) || !getClass().equals(object.getClass())) {
return false;
}

VdbSource other = (VdbSource)object;
return this.vdb.equals(other.vdb) && CoreStringUtil.equals(this.name, other.name) && CoreStringUtil.equals(this.translatorName, other.translatorName) && CoreStringUtil.equals(this.jndiName, other.jndiName) ;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

import static org.teiid.designer.vdb.Vdb.Event.MODEL_SOURCES;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import java.util.Iterator;
import java.util.List;

import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.vdb.manifest.SourceElement;

/**
*
Expand Down Expand Up @@ -47,7 +46,7 @@ public class VdbSourceInfo {

private Vdb vdb;

private Map<String, VdbSource> sources;
private List<VdbSource> sources;

private boolean supportsMultiSourceBindings;

Expand All @@ -62,21 +61,9 @@ public class VdbSourceInfo {
public VdbSourceInfo(final Vdb vdb) {
super();
this.vdb = vdb;
this.sources = new HashMap<String, VdbSource>();
this.sources = new ArrayList<VdbSource>();
}

/**
* @param vdb
* @param sources
*/
public VdbSourceInfo(final Vdb vdb, final Collection<SourceElement> sources) {
this(vdb);

for( SourceElement element : sources ) {
sources.add(element);
}
}

/**
* @return the vdb
*/
Expand All @@ -88,7 +75,7 @@ public Vdb getVdb() {
* @return the sources
*/
public Collection<VdbSource> getSources() {
return this.sources.values();
return this.sources;
}

/**
Expand All @@ -98,26 +85,10 @@ public Collection<VdbSource> getSources() {
* @return true if new VdbSource added
*/
public boolean add(String name, String jndiName, String translatorName) {
if(this.sources.get(name) == null ) {
this.sources.put(name, new VdbSource(getVdb(), name, jndiName, translatorName));
getVdb().setModified(this, MODEL_SOURCES, null, this.sources.get(name));
return true;
}

return false;
}

/**
* @param name
* @return true if new VdbSource removed
*/
public boolean remove(String name) {
CoreArgCheck.isNotNull(name, "name"); //$NON-NLS-1$

if(this.sources.get(name) != null ) {
VdbSource removedSource = this.sources.get(name);
this.sources.remove(name);
getVdb().setModified(this, MODEL_SOURCES, removedSource, null);
if( getSource(name) == null ) {
VdbSource vdbSource = new VdbSource(getVdb(), name, jndiName, translatorName);
this.sources.add(vdbSource);
getVdb().setModified(this, MODEL_SOURCES, null, vdbSource);
return true;
}

Expand All @@ -131,26 +102,35 @@ public boolean remove(String name) {
public boolean removeSource(VdbSource source) {
CoreArgCheck.isNotNull(source, "source"); //$NON-NLS-1$

if(this.sources.get(source.getName()) != null ) {
this.sources.remove(source.getName());
getVdb().setModified(this, MODEL_SOURCES, source, null);
return true;
Iterator iter = this.sources.iterator();
while(iter.hasNext()) {
VdbSource theSource = (VdbSource)iter.next();
if(theSource.getName().equalsIgnoreCase(source.getName())) {
iter.remove();
getVdb().setModified(this, MODEL_SOURCES, theSource, null);
return true;
}
}

return false;
}

/**
* @param name
* @return the VdbSource instance if it exists in the sources map
* Get the source with the specified name. If not in the source list, returns null
* @param name the source name
* @return the VdbSource
*/
public VdbSource getSource(String name) {
CoreArgCheck.isNotNull(name, "name"); //$NON-NLS-1$
CoreArgCheck.isNotEmpty(this.sources.values());

return this.sources.get(name);
private VdbSource getSource(String name) {
VdbSource result = null;
for(VdbSource source : this.sources) {
if(source.getName().equalsIgnoreCase(name)) {
result = source;
break;
}
}
return result;
}

/**
* @param index the source array index
* @return the VdbSource instance if it exists in the sources map
Expand All @@ -159,11 +139,9 @@ public VdbSource getSource(int index) {
if( sources.isEmpty() ) {
add(DEFAULT_SOURCE_NAME, null, null);
}
if(index < sources.size() ) {
for( int i=0; i<sources.size(); i++ ) {
VdbSource source = sources.values().iterator().next();
if( i == index ) return source;
}
if(index>=0 && index<sources.size() ) {
VdbSource source = sources.get(index);
return source;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import org.teiid.designer.vdb.VdbModelEntry;
import org.teiid.designer.vdb.VdbSource;

/**
Expand Down

0 comments on commit ce89134

Please sign in to comment.