Skip to content

Commit

Permalink
* Replaced various Property class definitions with single SimplePrope…
Browse files Browse the repository at this point in the history
…rty class

* Refactored IDialogStatusListener from relational to ui.common for re-use
  • Loading branch information
blafond committed Apr 24, 2014
1 parent 7dca46f commit 20a1d0e
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 343 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.core.translators;

/**
* Simple string name-value pair property object
*
*
*/
public class SimpleProperty {
private String name;
private String value;

public SimpleProperty(String name, String value) {
super();
this.name = name;
this.value = value;
}

/**
* @return the name
*/
public String getName() {
return this.name;
}

/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* @return the value
*/
public String getValue() {
return this.value;
}

/**
* @param value
* the value to set
*/
public void setValue(String value) {
this.value = value;
}

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

if (obj == null) {
return false;
}

if (!getClass().equals(obj.getClass())) {
return false;
}

return this.getName().equals(((SimpleProperty) obj).getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.swt.widgets.Text;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.core.designer.util.I18nUtil;
import org.teiid.designer.core.translators.SimpleProperty;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.datatools.ui.DatatoolsUiConstants;
import org.teiid.designer.datatools.ui.DatatoolsUiPlugin;
Expand Down Expand Up @@ -116,7 +117,7 @@ public Object[] getElements( Object inputElement ) {
return new Object[0];
}

List<HeaderPropertiesPanel.Property> properties= new ArrayList<HeaderPropertiesPanel.Property>();
List<SimpleProperty> properties= new ArrayList<SimpleProperty>();
for( Object key : props.keySet() ) {
String keyStr = (String)key;
if( ICredentialsCommon.PASSWORD_PROP_ID.equalsIgnoreCase(keyStr) ||
Expand All @@ -125,10 +126,10 @@ public Object[] getElements( Object inputElement ) {
IWSProfileConstants.END_POINT_URI_PROP_ID.equalsIgnoreCase(keyStr) ) {
// do nothing;
} else {
properties.add(new Property(keyStr, (String)props.get(key)));
properties.add(new SimpleProperty(keyStr, (String)props.get(key)));
}
}
return properties.toArray(new Property[0]);
return properties.toArray(new SimpleProperty[0]);
}

/**
Expand Down Expand Up @@ -157,8 +158,8 @@ public void inputChanged( Viewer viewer,
public int compare( Viewer viewer,
Object e1,
Object e2 ) {
Property prop1 = (Property)e1;
Property prop2 = (Property)e2;
SimpleProperty prop1 = (SimpleProperty)e1;
SimpleProperty prop2 = (SimpleProperty)e2;

return super.compare(viewer, prop1.getName(), prop2.getName());
}
Expand Down Expand Up @@ -242,14 +243,14 @@ void handlePropertySelected() {
this.removePropertyButton.setEnabled(hasSelection);
}

private Property getSelectedProperty() {
private SimpleProperty getSelectedProperty() {
IStructuredSelection selection = (IStructuredSelection)this.propertiesViewer.getSelection();

if (selection.isEmpty()) {
return null;
}

return (Property)selection.getFirstElement();
return (SimpleProperty)selection.getFirstElement();
}

void handleAddProperty() {
Expand All @@ -275,11 +276,11 @@ void handleAddProperty() {
// select the new property


Property prop = null;
SimpleProperty prop = null;

for(TableItem item : this.propertiesViewer.getTable().getItems() ) {
if( item.getData() instanceof Property && ((Property)item.getData()).getName().equals(name) ) {
prop = (Property)item.getData();
if( item.getData() instanceof SimpleProperty && ((SimpleProperty)item.getData()).getName().equals(name) ) {
prop = (SimpleProperty)item.getData();
break;
}
}
Expand All @@ -291,7 +292,7 @@ void handleAddProperty() {
}

void handleRemoveProperty() {
Property selectedProperty = getSelectedProperty();
SimpleProperty selectedProperty = getSelectedProperty();
assert (selectedProperty != null);

// update model
Expand All @@ -300,68 +301,6 @@ void handleRemoveProperty() {
// update UI
this.propertiesViewer.refresh();
}

class Property {
private String name;
private String value;

public Property(String name, String value) {
super();
this.name = name;
this.value = value;
}

/**
* @return the name
*/
public String getName() {
return this.name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* @return the value
*/
public String getValue() {
return this.value;
}

/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}

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

if (obj == null) {
return false;
}

if (!getClass().equals(obj.getClass())) {
return false;
}

return this.getName().equals(((Property)obj).getName());
}

}

class PropertyLabelProvider extends ColumnLabelProvider {

Expand All @@ -376,11 +315,11 @@ public PropertyLabelProvider( int columnID ) {
*/
@Override
public String getText(Object element) {
if( element instanceof Property ) {
if( element instanceof SimpleProperty ) {
if( columnID == 0 ) {
return ((Property)element).getName();
return ((SimpleProperty)element).getName();
} else if( columnID == 1 ) {
return ((Property)element).getValue();
return ((SimpleProperty)element).getValue();
}
}
return super.getText(element);
Expand Down Expand Up @@ -431,11 +370,11 @@ protected CellEditor getCellEditor(Object element) {
*/
@Override
protected Object getValue(Object element) {
if( element instanceof Property ) {
if( element instanceof SimpleProperty ) {
if( columnID == 0 ) {
return ((Property)element).getName();
return ((SimpleProperty)element).getName();
} else if( columnID == 1 ) {
return ((Property)element).getValue();
return ((SimpleProperty)element).getValue();
}
}
return 0;
Expand All @@ -449,19 +388,19 @@ protected Object getValue(Object element) {
*/
@Override
protected void setValue(Object element, Object value) {
if( element instanceof Property ) {
if( element instanceof SimpleProperty ) {
if( columnID == 0 ) {
String oldKey = ((Property)element).getName();
String oldValue = ((Property)element).getValue();
String oldKey = ((SimpleProperty)element).getName();
String oldValue = ((SimpleProperty)element).getValue();
String newKey = (String)value;
if( newKey != null && newKey.length() > 0 && !newKey.equalsIgnoreCase(oldKey)) {
profileProperties.remove(oldKey);
profileProperties.put(newKey,oldValue);
propertiesViewer.refresh();
}
} else if( columnID == 1 ) {
String key = ((Property)element).getName();
String oldValue = ((Property)element).getValue();
String key = ((SimpleProperty)element).getName();
String oldValue = ((SimpleProperty)element).getValue();
String newValue = (String)value;
if( newValue != null && newValue.length() > 0 && !newValue.equalsIgnoreCase(oldValue)) {
profileProperties.put(key,newValue);
Expand Down

0 comments on commit 20a1d0e

Please sign in to comment.