Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-04-26 09:06:59 -0400
committervlorenzo2013-04-26 09:06:59 -0400
commit14f699355b2a91f8c95f2b2109cf2a66070cf2d9 (patch)
treef5426a504c0d13fa48e67d7b14cae0bfd48d3d4b /sandbox
parent118a113822ffd8c1ebd1f46b176834ecf274c419 (diff)
downloadorg.eclipse.papyrus-14f699355b2a91f8c95f2b2109cf2a66070cf2d9.tar.gz
org.eclipse.papyrus-14f699355b2a91f8c95f2b2109cf2a66070cf2d9.tar.xz
org.eclipse.papyrus-14f699355b2a91f8c95f2b2109cf2a66070cf2d9.zip
401764: [Table 2] The classes managing the table model and Nattable must be refactored
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401764 Correct a small name error in the table metamodel + fix the synchronized tables
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractSynchronizedOnFeatureAxisManager.java164
1 files changed, 155 insertions, 9 deletions
diff --git a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractSynchronizedOnFeatureAxisManager.java b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractSynchronizedOnFeatureAxisManager.java
index a08591fa3e8..730c134de70 100644
--- a/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractSynchronizedOnFeatureAxisManager.java
+++ b/sandbox/TableV3/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractSynchronizedOnFeatureAxisManager.java
@@ -13,30 +13,87 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.nattable.manager.axis;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.EStructuralFeatureValueFillingConfiguration;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.IAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;
+import org.eclipse.swt.widgets.Display;
/**
*
* @author Vincent Lorenzo
*
*/
-public abstract class AbstractSynchronizedOnFeatureAxisManager extends AbstractAxisManager {
+public abstract class AbstractSynchronizedOnFeatureAxisManager extends AbstractAxisManager {//FIXME : this abstract class must inherits from the UML Element axis manager
/**
* the feature listener
*/
protected Adapter featureListener;
+ protected boolean isRefreshing = false;
+
+ protected EStructuralFeature currentListenFeature;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#init(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager,
+ * org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation,
+ * org.eclipse.papyrus.infra.nattable.model.nattable.Table,
+ * org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider, boolean)
+ *
+ * @param manager
+ * @param rep
+ * @param table
+ * @param provider
+ * @param mustRefreshOnAxisChanges
+ */
@Override
public void init(final INattableModelManager manager, final AxisManagerRepresentation rep, final Table table, final AbstractAxisProvider provider, boolean mustRefreshOnAxisChanges) {
super.init(manager, rep, table, provider, mustRefreshOnAxisChanges);
verifyValues();
+ this.currentListenFeature = getListenFeature();
+ addContextFeatureValueListener();
+ updateAxisContents();
+ }
+
+
+ protected void addContextFeatureValueListener() {
+ this.featureListener = new AdapterImpl() {
+
+ @Override
+ public void notifyChanged(Notification msg) {
+
+ if(msg.getFeature() == AbstractSynchronizedOnFeatureAxisManager.this.currentListenFeature) {//FIXME : create our own adapter for derived/subset feature
+ if(!AbstractSynchronizedOnFeatureAxisManager.this.isRefreshing) {//to avoid to many thread
+ AbstractSynchronizedOnFeatureAxisManager.this.isRefreshing = true;
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ updateAxisContents();
+ ((NattableModelManager)getTableManager()).refreshNattable();
+ AbstractSynchronizedOnFeatureAxisManager.this.isRefreshing = false;
+ }
+ });
+ }
+ }
+ };
+ };
+ getTable().getContext().eAdapters().add(this.featureListener);
}
/**
@@ -44,9 +101,46 @@ public abstract class AbstractSynchronizedOnFeatureAxisManager extends AbstractA
*
*/
protected void verifyValues() {
- //FIXME
- // assert getRepresentedContentProvider() instanceof EStructuralFeatureValueAxisProvider;
- // verifyCoupleContextFeature();
+ Assert.isNotNull(getFillingConfiguration() != null);
+ verifyCoupleContextFeature();
+ }
+
+ /**
+ *
+ * @return
+ * the feature to listen according to the current table configuration or <code>null</code> if it is not definedS
+ */
+ protected EStructuralFeature getListenFeature() {
+ final EStructuralFeatureValueFillingConfiguration config = getFillingConfiguration();
+ if(config != null) {
+ return config.getListenFeature();
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @return
+ * the filling configuration used by the table or <code>null</code> if any is defined
+ */
+ protected EStructuralFeatureValueFillingConfiguration getFillingConfiguration() {//FIXME : local configuration not yet managed
+ for(final IAxisConfiguration current : this.rep.getSpecificAxisConfigurations()) {
+ if(current instanceof EStructuralFeatureValueFillingConfiguration) {
+ return (EStructuralFeatureValueFillingConfiguration)current;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ getTable().getContext().eAdapters().remove(this.featureListener);
+ super.dispose();
}
/**
@@ -54,11 +148,11 @@ public abstract class AbstractSynchronizedOnFeatureAxisManager extends AbstractA
*
*/
protected void verifyCoupleContextFeature() {
- //FIXME
- // final EStructuralFeature feature = ((EStructuralFeatureValueAxisProvider)getRepresentedContentProvider()).getListenFeature();
- // assert feature.isMany();
- // final EObject context = getTable().getContext();
- // assert context.eClass().getEAllReferences().contains(feature);
+ final EStructuralFeature feature = getListenFeature();
+ if(feature != null) {
+ Assert.isTrue(feature.isMany());
+ Assert.isTrue(getTable().getContext().eClass().getEAllStructuralFeatures().contains(feature));
+ }
}
/**
@@ -85,4 +179,56 @@ public abstract class AbstractSynchronizedOnFeatureAxisManager extends AbstractA
public boolean canInsertAxis(Collection<Object> objectsToAdd, int index) {
return false;
}
+
+ /**
+ * calculus of the contents of the axis
+ */
+ @Override
+ public synchronized void updateAxisContents() {
+ final EObject context = getTable().getContext();
+ Object value;
+ if(this.currentListenFeature != null) {
+ value = context.eGet(this.currentListenFeature);
+ } else {
+ value = context.eGet(getListenFeature());
+ }
+ assert value instanceof List<?>;
+ List<Object> interestingObject = filterObject((List<?>)value);
+ interestingObject = sortObjects(interestingObject);
+ final List<Object> axisElements = getTableManager().getElementsList(getRepresentedContentProvider());
+ axisElements.clear();
+ Iterator<Object> iter = interestingObject.iterator();
+ while(iter.hasNext()) {
+ axisElements.add(iter.next());
+ }
+ }
+
+ /**
+ *
+ * @param objects
+ * @return
+ */
+ protected List<Object> sortObjects(final Collection<Object> objects) {
+ return new ArrayList<Object>(objects);
+ }
+
+ /**
+ *
+ * @param objects
+ * @return
+ */
+ protected List<Object> filterObject(final List<?> objects) {
+ return new ArrayList<Object>(objects);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#canReoderElements()
+ *
+ * @return
+ */
+ @Override
+ public boolean canReoderElements() {
+ return false;
+ }
}

Back to the top