+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
package org.simantics.sysdyn.ui.properties;\r
\r
import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.events.DisposeEvent;\r
+import org.eclipse.swt.events.DisposeListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.IWorkbenchSite;\r
import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
import org.simantics.db.AsyncReadGraph;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.procedure.AsyncListener;\r
import org.simantics.db.request.Read;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
import org.simantics.utils.datastructures.Callback;\r
\r
public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl {\r
\r
+ private boolean isDisposed = false;\r
\r
+ \r
+ public void createControl(Composite parent, final IWorkbenchSite site, final ISessionContext context, final WidgetSupportImpl support) {\r
+ super.createControl(parent, site, context, support);\r
+ \r
+ // Add dispose listener to make sure name listening receives the correct isDisposed -value\r
+ parent.addDisposeListener(new DisposeListener() {\r
+ \r
+ @Override\r
+ public void widgetDisposed(DisposeEvent e) {\r
+ LabelPropertyTabContributor.this.dispose();\r
+ }\r
+ });\r
+ }\r
+ \r
+ @Override\r
public void updatePartName(ISelection forSelection, final Callback<String> updateCallback) {\r
- final Resource r = AdaptionUtils.adaptToSingle(forSelection, Resource.class);\r
- if(r == null) {\r
+ final Resource resource = AdaptionUtils.adaptToSingle(forSelection, Resource.class);\r
+ if(resource == null) {\r
updateCallback.run("Selection properties");\r
return;\r
}\r
@Override\r
public String perform(ReadGraph graph) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+ Resource r = resource;\r
+ if(graph.hasStatement(r, mr.ElementToComponent)) {\r
+ r = graph.getSingleObject(r, mr.ElementToComponent);\r
+ }\r
String label = graph.getPossibleRelatedValue(r, l0.HasLabel);\r
if(label != null)\r
return label;\r
\r
@Override\r
public boolean isDisposed() {\r
- return false;\r
+ return isDisposed;\r
}\r
});\r
} catch (DatabaseException e) {\r
}\r
\r
}\r
+ \r
+ @Override\r
+ protected void dispose() {\r
+ this.isDisposed = true;\r
+ }\r
}\r