-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.project.features;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.common.processor.MergingGraphRequestProcessor;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.project.IProject;\r
-import org.simantics.project.exception.ProjectException;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-\r
-\r
-/**\r
- * Implement {@link #configure()} and {@link #deconfigure()} to customize\r
- * how a feature configures the project in question.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class AbstractProjectFeature implements IProjectFeature {\r
-\r
- private IProject project;\r
-\r
- public AbstractProjectFeature() {\r
- }\r
-\r
- protected void assertProject() {\r
- if (project == null)\r
- throw new IllegalStateException("project element is null");\r
- }\r
-\r
- @Override\r
- public IProject getProjectElement() {\r
- return project;\r
- }\r
-\r
- public IProject getProject() {\r
- assertProject();\r
- return project;\r
- }\r
-\r
- public IProject peekProject() {\r
- return project;\r
- }\r
-\r
- protected Session getSession() {\r
- IProject p = getProject();\r
- Session s = p.getSession();\r
- if (s == null)\r
- throw new IllegalStateException("project not attached to a database session");\r
- return s;\r
- }\r
-\r
- protected Session peekSession() {\r
- IProject p = peekProject();\r
- if (p == null)\r
- return null;\r
- return p.getSession();\r
- }\r
-\r
- protected RequestProcessor getGraphRequestProcessor() {\r
- IProject p = peekProject();\r
- if (p == null)\r
- return null;\r
- Session s = p.getSession();\r
- //MergingGraphRequestProcessor mgrp = s.getService(MergingGraphRequestProcessor.class);\r
- MergingGraphRequestProcessor mgrp = null;\r
- return mgrp != null ? mgrp : s;\r
- }\r
-\r
- @Override\r
- public void setProjectElement(IProject project) {\r
- this.project = project;\r
- }\r
-\r
- public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException {\r
- }\r
-\r
- @Override\r
- public void configure() throws ProjectException {\r
- try {\r
- getSession().syncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- onActivated(graph, getProject());\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- throw new ProjectException(e);\r
- }\r
- }\r
-\r
- @Override\r
- public void deconfigure() throws ProjectException {\r
- }\r
-\r
- protected <T> void addToCollectionHint(Key key, T... ts) {\r
- Collection<T> c = getProjectElement().getHint(key);\r
- if (c == null) {\r
- c = new ArrayList<T>();\r
- getProjectElement().setHint(key, c);\r
- }\r
- for (T t : ts)\r
- c.add(t);\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.project.features;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Session;
+import org.simantics.db.common.processor.MergingGraphRequestProcessor;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.project.IProject;
+import org.simantics.project.exception.ProjectException;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+
+
+/**
+ * Implement {@link #configure()} and {@link #deconfigure()} to customize
+ * how a feature configures the project in question.
+ *
+ * @author Tuukka Lehtonen
+ */
+public abstract class AbstractProjectFeature implements IProjectFeature {
+
+ private IProject project;
+
+ public AbstractProjectFeature() {
+ }
+
+ protected void assertProject() {
+ if (project == null)
+ throw new IllegalStateException("project element is null");
+ }
+
+ @Override
+ public IProject getProjectElement() {
+ return project;
+ }
+
+ public IProject getProject() {
+ assertProject();
+ return project;
+ }
+
+ public IProject peekProject() {
+ return project;
+ }
+
+ protected Session getSession() {
+ IProject p = getProject();
+ Session s = p.getSession();
+ if (s == null)
+ throw new IllegalStateException("project not attached to a database session");
+ return s;
+ }
+
+ protected Session peekSession() {
+ IProject p = peekProject();
+ if (p == null)
+ return null;
+ return p.getSession();
+ }
+
+ protected RequestProcessor getGraphRequestProcessor() {
+ IProject p = peekProject();
+ if (p == null)
+ return null;
+ Session s = p.getSession();
+ //MergingGraphRequestProcessor mgrp = s.getService(MergingGraphRequestProcessor.class);
+ MergingGraphRequestProcessor mgrp = null;
+ return mgrp != null ? mgrp : s;
+ }
+
+ @Override
+ public void setProjectElement(IProject project) {
+ this.project = project;
+ }
+
+ public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException {
+ }
+
+ @Override
+ public void configure() throws ProjectException {
+ try {
+ getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ onActivated(graph, getProject());
+ }
+ });
+ } catch (DatabaseException e) {
+ throw new ProjectException(e);
+ }
+ }
+
+ @Override
+ public void deconfigure() throws ProjectException {
+ }
+
+ protected <T> void addToCollectionHint(Key key, T... ts) {
+ Collection<T> c = getProjectElement().getHint(key);
+ if (c == null) {
+ c = new ArrayList<T>();
+ getProjectElement().setHint(key, c);
+ }
+ for (T t : ts)
+ c.add(t);
+ }
+
+}