summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorLukas Ladenberger2012-03-26 12:29:59 (EDT)
committer Michael Jastram2012-04-05 06:31:38 (EDT)
commit374efc81cb924cb923031fab2d15ab87c679b2e4 (patch)
tree0c857694dbf2d26823a80aee6dd172c43bb4f98c
parentcf9b6b21e06255b28552f73db3b74a710cc6a76f (diff)
downloadorg.eclipse.rmf-374efc81cb924cb923031fab2d15ab87c679b2e4.zip
org.eclipse.rmf-374efc81cb924cb923031fab2d15ab87c679b2e4.tar.gz
org.eclipse.rmf-374efc81cb924cb923031fab2d15ab87c679b2e4.tar.bz2
fixed #368254 (Sort PropertyView)
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellEditorProvider.java4
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellRendererProvider.java7
-rw-r--r--org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyContentProvider.java195
3 files changed, 137 insertions, 69 deletions
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellEditorProvider.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellEditorProvider.java
index 1221b5a..d7bff5a 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellEditorProvider.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellEditorProvider.java
@@ -70,7 +70,7 @@ public class ProrPropertyCellEditorProvider extends AbstractProrCellEditorProvid
return service.canEdit();
} else {
IItemPropertyDescriptor descriptor = this.contentProvider
- .getItemPropertyDescriptor(row);
+ .getItemPropertyDescriptor(row).getItemPropertyDescriptor();
if (descriptor != null)
return descriptor.canSetProperty(this.contentProvider
.getIdentifiable());
@@ -109,7 +109,7 @@ public class ProrPropertyCellEditorProvider extends AbstractProrCellEditorProvid
// exists) return a default celleditor
final IItemPropertyDescriptor descriptor = this.contentProvider
- .getItemPropertyDescriptor(row);
+ .getItemPropertyDescriptor(row).getItemPropertyDescriptor();
final Identifiable selectedElement = this.contentProvider.getIdentifiable();
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellRendererProvider.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellRendererProvider.java
index bbf56b7..44c4137 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellRendererProvider.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyCellRendererProvider.java
@@ -17,7 +17,8 @@ import org.agilemore.agilegrid.SWTResourceManager;
import org.agilemore.agilegrid.renderers.TextCellRenderer;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
+import org.eclipse.rmf.pror.reqif10.editor.propertiesview.ProrPropertyContentProvider.ItemCategory;
+import org.eclipse.rmf.pror.reqif10.editor.propertiesview.ProrPropertyContentProvider.SortedItemPropertyDescriptor;
import org.eclipse.swt.SWT;
public class ProrPropertyCellRendererProvider extends DefaultCellRendererProvider {
@@ -43,11 +44,11 @@ public class ProrPropertyCellRendererProvider extends DefaultCellRendererProvide
.getContentProvider()).getRowContent(row);
// If we have a category at this row, return the category cell renderer
- if (col == 0 && obj instanceof String) {
+ if (col <= 1 && obj instanceof ItemCategory) {
return this.categoryCellRenderer;
// else if we have an item property descriptor at this row, return
// the corresponding default cell renderer for attribute/value rows
- } else if (col == 1 && obj instanceof IItemPropertyDescriptor) {
+ } else if (col == 1 && obj instanceof SortedItemPropertyDescriptor) {
return this.attributeCellRenderer;
// else return the default agile grid cell renderer
} else {
diff --git a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyContentProvider.java b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyContentProvider.java
index 027ba80..32759c9 100644
--- a/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyContentProvider.java
+++ b/org.eclipse.rmf.pror.reqif10.editor/src/org/eclipse/rmf/pror/reqif10/editor/propertiesview/ProrPropertyContentProvider.java
@@ -11,6 +11,7 @@
package org.eclipse.rmf.pror.reqif10.editor.propertiesview;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -43,8 +44,19 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
private Identifiable identifiable;
// This is only a help HashMap for storing temporarily the item categories
- private HashMap<String, ItemCategory> categories;
+ private HashMap<String, ItemCategory> customCategories;
+ public static String SPEC_HIERARCHY_NAME = "Spec Hierarchy";
+ public static String SPEC_OBJECT_NAME = "Spec Object";
+ public static String SPEC_RELATION_NAME = "Spec Relation";
+
+ private ItemCategory specHierarchyItemCategory = new ItemCategory(
+ SPEC_HIERARCHY_NAME);
+ private ItemCategory specObjectItemCategory = new ItemCategory(
+ SPEC_OBJECT_NAME);
+ private ItemCategory specRelationItemCategory = new ItemCategory(
+ SPEC_RELATION_NAME);
+
// HashMap for storing the row with the corresponding object
private HashMap<Integer, Object> rows;
@@ -52,10 +64,14 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
public ProrPropertyContentProvider(EditingDomain editingDomain) {
this.editingDomain = (AdapterFactoryEditingDomain) editingDomain;
- this.categories = new HashMap<String, ItemCategory>();
+ this.customCategories = new HashMap<String, ItemCategory>();
this.rows = new HashMap<Integer, Object>();
}
+ /**
+ * This method is responsible for displaying the right content at the given
+ * row and col.
+ */
@Override
public Object doGetContentAt(int row, int col) {
@@ -70,19 +86,24 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
switch (col) {
case 0:
- if (element instanceof String) { // Category
- return element;
- } else { // Attribute
- return ((IItemPropertyDescriptor) element)
- .getDisplayName(this.identifiable);
+ if (element instanceof ItemCategory) { // Category Name
+ return ((ItemCategory) element).getCategoryName();
+ } else if (element instanceof SortedItemPropertyDescriptor) { // Attribute
+ SortedItemPropertyDescriptor descriptor = (SortedItemPropertyDescriptor) element;
+ if (descriptor.getItemPropertyDescriptor() != null) {
+ return descriptor.getItemPropertyDescriptor()
+ .getDisplayName(identifiable);
+ }
}
case 1:
- AttributeValue atrValue = getAttributeValue((IItemPropertyDescriptor) element);
- if (atrValue != null) {
- return atrValue;
- } else {
- return getItemLabelProvider(row).getText(
- getItemPropertyValue(row));
+ if (element instanceof SortedItemPropertyDescriptor) {
+ AttributeValue atrValue = getAttributeValue((SortedItemPropertyDescriptor) element);
+ if (atrValue != null) {
+ return atrValue;
+ } else {
+ return getItemLabelProvider(row).getText(
+ getItemPropertyValue(row));
+ }
}
default:
break;
@@ -112,7 +133,10 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
this.identifiable = identifiable;
- this.categories.clear();
+ this.customCategories.clear();
+ this.specHierarchyItemCategory.getDescriptors().clear();
+ this.specObjectItemCategory.getDescriptors().clear();
+ this.specRelationItemCategory.getDescriptors().clear();
this.rows.clear();
if (identifiable != null) {
@@ -135,34 +159,56 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
if (categoryName == null)
categoryName = DEFAULT_CATEGORY_NAME;
- ItemCategory category;
+ ItemCategory customCategory;
+
- if (!this.categories.containsKey(categoryName)) {
- category = new ItemCategory(categoryName, identifiable);
- category.addDescriptor(descriptor);
- this.categories.put(categoryName, category);
+ if (categoryName.equals(SPEC_HIERARCHY_NAME)) {
+ specHierarchyItemCategory.addDescriptor(descriptor,
+ identifiable);
+ } else if (categoryName.equals(SPEC_OBJECT_NAME)) {
+ specObjectItemCategory.addDescriptor(descriptor,
+ identifiable);
+ } else if (categoryName.equals(SPEC_RELATION_NAME)) {
+ specRelationItemCategory.addDescriptor(descriptor,
+ identifiable);
} else {
- category = this.categories.get(categoryName);
- category.addDescriptor(descriptor);
+ if (!this.customCategories.containsKey(categoryName)) {
+ customCategory = new ItemCategory(categoryName);
+ customCategory.addDescriptor(descriptor, identifiable);
+ this.customCategories.put(categoryName, customCategory);
+ } else {
+ customCategory = this.customCategories.get(categoryName);
+ customCategory.addDescriptor(descriptor, identifiable);
+ }
}
- }
- int i = 0;
- for (ItemCategory cat : this.categories.values()) {
- String catName = cat.getCategoryName();
- this.rows.put(i, catName);
- i = i + 1;
- for (IItemPropertyDescriptor des : cat.getDescriptors()) {
- this.rows.put(i, des);
- i = i + 1;
- }
}
+ for (ItemCategory cat : customCategories.values())
+ addItemCategory(cat);
+ addItemCategory(specObjectItemCategory);
+ addItemCategory(specHierarchyItemCategory);
+ addItemCategory(specRelationItemCategory);
+
}
}
+ private void addItemCategory(ItemCategory cat) {
+ if (cat.getDescriptors().size() == 0)
+ return;
+ int size = this.rows.size();
+ this.rows.put(size, cat);
+ size = size + 1;
+ Collections.sort(cat.getDescriptors());
+ for (SortedItemPropertyDescriptor des : cat
+ .getDescriptors()) {
+ this.rows.put(size, des);
+ size = size + 1;
+ }
+ }
+
/**
* Returns the current selected specification element. This could be i.e. an
* instance of {@link SpecObject}, {@link SpecRelation} or
@@ -175,16 +221,16 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
}
/**
- * Returns the {@link IItemPropertyDescriptor} of the row's object.
+ * Returns the {@link SortedItemPropertyDescriptor} of the row's object.
*
* @param row
- * @return an instance of {@link IItemPropertyDescriptor}
+ * @return an instance of {@link SortedItemPropertyDescriptor}
*/
- public IItemPropertyDescriptor getItemPropertyDescriptor(int row) {
+ public SortedItemPropertyDescriptor getItemPropertyDescriptor(int row) {
if (this.identifiable != null) {
Object obj = this.rows.get(row);
- if (obj instanceof IItemPropertyDescriptor) {
- return (IItemPropertyDescriptor) obj;
+ if (obj instanceof SortedItemPropertyDescriptor) {
+ return (SortedItemPropertyDescriptor) obj;
}
}
return null;
@@ -197,8 +243,12 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
* @return an instance of {@link IItemLabelProvider}
*/
public IItemLabelProvider getItemLabelProvider(int row) {
- return getItemPropertyDescriptor(row)
+ IItemPropertyDescriptor itemPropertyDescriptor = getItemPropertyDescriptor(
+ row).getItemPropertyDescriptor();
+ if (itemPropertyDescriptor != null)
+ return itemPropertyDescriptor
.getLabelProvider(this.identifiable);
+ return null;
}
/**
@@ -208,7 +258,7 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
* @return the property value
*/
public Object getItemPropertyValue(int row) {
- return getItemPropertyDescriptor(row)
+ return getItemPropertyDescriptor(row).getItemPropertyDescriptor()
.getPropertyValue(this.identifiable);
}
@@ -225,22 +275,24 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
*/
public AttributeValue getAttributeValue(int row) {
Object obj = this.rows.get(row);
- if (obj instanceof IItemPropertyDescriptor) {
- return getAttributeValue((IItemPropertyDescriptor) obj);
+ if (obj instanceof SortedItemPropertyDescriptor) {
+ return getAttributeValue((SortedItemPropertyDescriptor) obj);
}
return null;
}
- public AttributeValue getAttributeValue(IItemPropertyDescriptor descriptor) {
+ private AttributeValue getAttributeValue(
+ SortedItemPropertyDescriptor descriptor) {
SpecElementWithAttributes sepcAtr = null;
if (this.identifiable instanceof SpecElementWithAttributes) {
sepcAtr = (SpecElementWithAttributes) this.identifiable;
} else if (this.identifiable instanceof SpecHierarchy) {
sepcAtr = ((SpecHierarchy) this.identifiable).getObject();
}
- if (sepcAtr != null)
- return Reqif10Util.getAttributeValueForLabel(sepcAtr,
- descriptor.getDisplayName(sepcAtr));
+ if (sepcAtr != null && descriptor.getItemPropertyDescriptor() != null) {
+ return Reqif10Util.getAttributeValueForLabel(sepcAtr, descriptor
+ .getItemPropertyDescriptor().getDisplayName(sepcAtr));
+ }
return null;
}
@@ -250,19 +302,16 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
/**
* Helper class for storing category with corresponding
- * {@link IItemPropertyDescriptor}'s.
+ * {@link SortedItemPropertyDescriptor}'s.
*/
class ItemCategory {
private String categoryName;
- private ArrayList<IItemPropertyDescriptor> descriptors;
+ private ArrayList<SortedItemPropertyDescriptor> descriptors;
- private Identifiable specElement;
-
- public ItemCategory(String categoryName, Identifiable specElement) {
+ public ItemCategory(String categoryName) {
this.categoryName = categoryName;
- this.descriptors = new ArrayList<IItemPropertyDescriptor>();
- this.specElement = specElement;
+ this.descriptors = new ArrayList<SortedItemPropertyDescriptor>();
}
public void setCategoryName(String categoryName) {
@@ -273,25 +322,43 @@ public class ProrPropertyContentProvider extends AbstractContentProvider {
return categoryName;
}
- public ArrayList<IItemPropertyDescriptor> getDescriptors() {
+ public ArrayList<SortedItemPropertyDescriptor> getDescriptors() {
return descriptors;
}
- public void addDescriptor(IItemPropertyDescriptor descriptor) {
- this.descriptors.add(descriptor);
+ public void addDescriptor(IItemPropertyDescriptor descriptor, Identifiable specElement) {
+ this.descriptors.add(new SortedItemPropertyDescriptor(descriptor,
+ specElement));
}
- @Override
- public String toString() {
-
- StringBuffer sb = new StringBuffer();
- sb.append("Category name: " + categoryName + "\n");
- for (IItemPropertyDescriptor descriptor : this.descriptors) {
- sb.append(" --> " + descriptor.getDisplayName(this.specElement)
- + "\n");
- }
- return sb.toString();
+ }
+
+ /**
+ * HelpercClass for sorting the {@link IItemPropertyDescriptor}s in the
+ * categories.
+ */
+ class SortedItemPropertyDescriptor implements
+ Comparable<SortedItemPropertyDescriptor> {
+
+ private IItemPropertyDescriptor itemPropertyDescriptor;
+ private Identifiable specElement;
+
+ public SortedItemPropertyDescriptor(
+ IItemPropertyDescriptor itemPropertyDescriptor,
+ Identifiable specElement) {
+ this.itemPropertyDescriptor = itemPropertyDescriptor;
+ this.specElement = specElement;
+ }
+
+ public int compareTo(SortedItemPropertyDescriptor o) {
+ return itemPropertyDescriptor.getDisplayName(specElement)
+ .compareTo(
+ o.itemPropertyDescriptor
+ .getDisplayName(o.specElement));
+ }
+ public IItemPropertyDescriptor getItemPropertyDescriptor() {
+ return itemPropertyDescriptor;
}
}