From f849ce1cbf82858b0a1eca87197477a23a7570e4 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Fri, 22 Jan 2016 09:57:33 +0000
Subject: [PATCH] Added EclipseResourceStorageProvider introspection with UI.
 refs 2460

---
 .../details/KISSDetailsUIRegistry.java        |   4 +
 ...ProviderIntrospectionDetailsUIHandler.java | 134 ++++++++++++++++++
 ...eServiceIntrospectionDetailsUIHandler.java |   2 +-
 .../EclipseResourceStorageProvider.java       |  12 +-
 ...orageProviderIntrospectionDetailsItem.java |  83 +++++++++++
 5 files changed, 230 insertions(+), 5 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/EclipseResourceStorageProviderIntrospectionDetailsUIHandler.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/introspection/items/EclipseResourceStorageProviderIntrospectionDetailsItem.java

diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java
index 1defbae17..8367b1632 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/KISSDetailsUIRegistry.java
@@ -23,12 +23,14 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
 import org.fortiss.tooling.kernel.introspection.items.ConnectionCompositorServiceIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.items.ConstraintCheckerServiceIntrospectionDetailsItem;
+import org.fortiss.tooling.kernel.introspection.items.EclipseResourceStorageProviderIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.items.PersistencyServiceIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.items.PrototypeServiceIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.items.TransformationServiceIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConnectionCompositorServiceIntrospectionDetailsUIHandler;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ConstraintCheckerServiceIntrospectionDetailsUIHandler;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.ContextMenuServiceIntrospectionDetailsUIHandler;
+import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.EclipseResourceStorageProviderIntrospectionDetailsUIHandler;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.PersistencyServiceIntrospectionDetailsUIHandler;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.PrototypeServiceIntrospectionDetailsUIHandler;
 import org.fortiss.tooling.kernel.ui.internal.introspection.details.handler.TransformationServiceIntrospectionDetailsUIHandler;
@@ -59,6 +61,8 @@ public final class KISSDetailsUIRegistry {
 				new ConstraintCheckerServiceIntrospectionDetailsUIHandler());
 		registerHandler(ContextMenuServiceIntrospectionDetailsItem.class,
 				new ContextMenuServiceIntrospectionDetailsUIHandler());
+		registerHandler(EclipseResourceStorageProviderIntrospectionDetailsItem.class,
+				new EclipseResourceStorageProviderIntrospectionDetailsUIHandler());
 		registerHandler(PrototypeServiceIntrospectionDetailsItem.class,
 				new PrototypeServiceIntrospectionDetailsUIHandler());
 		registerHandler(PersistencyServiceIntrospectionDetailsItem.class,
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/EclipseResourceStorageProviderIntrospectionDetailsUIHandler.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/EclipseResourceStorageProviderIntrospectionDetailsUIHandler.java
new file mode 100644
index 000000000..faca8d8d6
--- /dev/null
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/EclipseResourceStorageProviderIntrospectionDetailsUIHandler.java
@@ -0,0 +1,134 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.ui.internal.introspection.details.handler;
+
+import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TableLabelProviderBase;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.fortiss.tooling.kernel.extension.IEclipseResourcePostLoadProvider;
+import org.fortiss.tooling.kernel.extension.IEclipseResourceStorageLocationProvider;
+import org.fortiss.tooling.kernel.extension.data.ModelStorageError;
+import org.fortiss.tooling.kernel.introspection.items.EclipseResourceStorageProviderIntrospectionDetailsItem;
+
+/**
+ * Introspection UI handler for the {@link EclipseResourceStorageProviderIntrospectionDetailsItem}s.
+ * 
+ * @author hoelzl
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating RED Hash:
+ */
+public final class EclipseResourceStorageProviderIntrospectionDetailsUIHandler extends
+		IntrospectionDetailsUIHandlerBase {
+
+	/** {@inheritDoc} */
+	@Override
+	public Control createComposite(ScrolledComposite parent) {
+		return createFilteredTree(parent, "Type to search registered persistency providers:", null);
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected void createTreeColumns(Tree tree) {
+		TreeColumn col0 = new TreeColumn(tree, SWT.LEFT);
+		col0.setText("Category / Provider / File");
+		col0.setWidth(450);
+
+		TreeColumn col1 = new TreeColumn(tree, SWT.LEFT);
+		col1.setText("Implementation Class / Path / Storage Error Message");
+		col1.setWidth(400);
+	}
+
+	/** String array of root categories. */
+	private final String[] ROOT_CATEGORY = new String[] {"Storage Provider", "Post-load Provider",
+			"Loaded Files", "Erroneous Files"};
+
+	/** {@inheritDoc} */
+	@Override
+	protected ITreeContentProvider createContentProvider() {
+		return new TreeContentProviderBase() {
+
+			@Override
+			public Object[] getChildren(Object parentElement) {
+				if(parentElement == getInputObject()) {
+					return ROOT_CATEGORY;
+				}
+				if(ROOT_CATEGORY[0].equals(parentElement)) {
+					return getInputObject().getStorageProviderList().toArray();
+				}
+				if(ROOT_CATEGORY[1].equals(parentElement)) {
+					return getInputObject().getPostLoadProviderList().toArray();
+				}
+				if(ROOT_CATEGORY[2].equals(parentElement)) {
+					return getInputObject().getLoadedFiles().toArray();
+				}
+				if(ROOT_CATEGORY[3].equals(parentElement)) {
+					return getInputObject().getErrorFiles().toArray();
+				}
+				return null;
+			}
+		};
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected ITableLabelProvider createLabelProvider() {
+		return new TableLabelProviderBase() {
+			@Override
+			public String getColumnText(Object parentElement, int columnIndex) {
+				if(parentElement instanceof IEclipseResourceStorageLocationProvider ||
+						parentElement instanceof IEclipseResourcePostLoadProvider) {
+					return columnIndex == 0 ? parentElement.getClass().getSimpleName()
+							: parentElement.getClass().getName();
+				}
+				if(parentElement instanceof String) {
+					return columnIndex == 0 ? (String)parentElement : "";
+				}
+				if(parentElement instanceof IFile) {
+					IFile file = (IFile)parentElement;
+					return columnIndex == 0 ? file.getName() : file.getFullPath().toString();
+				}
+				if(parentElement instanceof ModelStorageError) {
+					ModelStorageError error = (ModelStorageError)parentElement;
+					return columnIndex == 0 ? "" : error.getMessage();
+				}
+				return "";
+			}
+		};
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected PatternFilter createPatternFilter() {
+		return new TableViewerPatternFilter();
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	protected EclipseResourceStorageProviderIntrospectionDetailsItem getInputObject() {
+		return (EclipseResourceStorageProviderIntrospectionDetailsItem)dataItem;
+	}
+}
diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/PrototypeServiceIntrospectionDetailsUIHandler.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/PrototypeServiceIntrospectionDetailsUIHandler.java
index 1372b0289..7c54b0e0d 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/PrototypeServiceIntrospectionDetailsUIHandler.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/introspection/details/handler/PrototypeServiceIntrospectionDetailsUIHandler.java
@@ -46,7 +46,7 @@ public final class PrototypeServiceIntrospectionDetailsUIHandler extends
 	/** {@inheritDoc} */
 	@Override
 	public Control createComposite(ScrolledComposite parent) {
-		String heading = "Type to serach registered providers:";
+		String heading = "Type to search registered providers:";
 		String footer =
 				"Number of currently registered prototypes: " +
 						IPrototypeService.INSTANCE.getAllPrototypes().size() + " (" +
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java
index bc180452e..01ccfb7ae 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java
@@ -17,6 +17,9 @@ $Id$
 +--------------------------------------------------------------------------*/
 package org.fortiss.tooling.kernel.internal.storage.eclipse;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.unmodifiableList;
+import static java.util.Collections.unmodifiableSet;
 import static org.eclipse.core.resources.IResourceDelta.ADDED;
 import static org.eclipse.core.resources.IResourceDelta.CHANGED;
 import static org.eclipse.core.resources.IResourceDelta.REMOVED;
@@ -63,6 +66,7 @@ import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.introspection.IIntrospectionItem;
 import org.fortiss.tooling.kernel.introspection.IIntrospectiveKernelService;
 import org.fortiss.tooling.kernel.introspection.KernelIntrospectionSystemService;
+import org.fortiss.tooling.kernel.introspection.items.EclipseResourceStorageProviderIntrospectionDetailsItem;
 import org.fortiss.tooling.kernel.service.IEclipseResourceStorageService;
 import org.fortiss.tooling.kernel.service.IMigrationService;
 import org.fortiss.tooling.kernel.service.IPersistencyService;
@@ -403,15 +407,15 @@ public class EclipseResourceStorageProvider implements IEclipseResourceStorageSe
 	/** {@inheritDoc} */
 	@Override
 	public Collection<IIntrospectionItem> getIntrospectionItems() {
-		// TODO continue HERE
-		return null;
+		return emptyList();
 	}
 
 	/** {@inheritDoc} */
 	@Override
 	public IIntrospectionDetailsItem getDetailsItem() {
-		// TODO continue HERE
-		return null;
+		return new EclipseResourceStorageProviderIntrospectionDetailsItem(
+				unmodifiableList(storageProviderList), unmodifiableList(postLoadProviderList),
+				unmodifiableSet(loadedContexts.keySet()), unmodifiableList(errorFiles));
 	}
 
 	/** {@inheritDoc} */
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/introspection/items/EclipseResourceStorageProviderIntrospectionDetailsItem.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/introspection/items/EclipseResourceStorageProviderIntrospectionDetailsItem.java
new file mode 100644
index 000000000..dc678fb00
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/introspection/items/EclipseResourceStorageProviderIntrospectionDetailsItem.java
@@ -0,0 +1,83 @@
+/*--------------------------------------------------------------------------+
+$Id$
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.introspection.items;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.fortiss.tooling.kernel.extension.IEclipseResourcePostLoadProvider;
+import org.fortiss.tooling.kernel.extension.IEclipseResourceStorageLocationProvider;
+import org.fortiss.tooling.kernel.extension.data.ModelStorageError;
+import org.fortiss.tooling.kernel.internal.storage.eclipse.EclipseResourceStorageProvider;
+import org.fortiss.tooling.kernel.introspection.IIntrospectionDetailsItem;
+
+/**
+ * {@link IIntrospectionDetailsItem} class for {@link EclipseResourceStorageProvider}.
+ * 
+ * @author hoelzl
+ * @author $Author$
+ * @version $Rev$
+ * @ConQAT.Rating RED Hash:
+ */
+public final class EclipseResourceStorageProviderIntrospectionDetailsItem implements
+		IIntrospectionDetailsItem {
+
+	/** Stores the registered storage providers. */
+	private final List<IEclipseResourceStorageLocationProvider> storageProviderList;
+
+	/** Stores the registered post loading providers. */
+	private final List<IEclipseResourcePostLoadProvider> postLoadProviderList;
+
+	/** Cache of models loaded so far. */
+	private final Collection<IFile> loadedContexts;
+
+	/** List of failed model storage files. */
+	private final List<ModelStorageError> errorFiles;
+
+	/** Constructor. */
+	public EclipseResourceStorageProviderIntrospectionDetailsItem(
+			List<IEclipseResourceStorageLocationProvider> storageProviderList,
+			List<IEclipseResourcePostLoadProvider> postLoadProviderList,
+			Collection<IFile> loadedContexts, List<ModelStorageError> errorFiles) {
+		this.storageProviderList = storageProviderList;
+		this.postLoadProviderList = postLoadProviderList;
+		this.loadedContexts = loadedContexts;
+		this.errorFiles = errorFiles;
+	}
+
+	/** Returns the storage provider list. */
+	public List<IEclipseResourceStorageLocationProvider> getStorageProviderList() {
+		return storageProviderList;
+	}
+
+	/** Returns the post load provider list. */
+	public List<IEclipseResourcePostLoadProvider> getPostLoadProviderList() {
+		return postLoadProviderList;
+	}
+
+	/** Returns the loaded contexts. */
+	public Collection<IFile> getLoadedFiles() {
+		return loadedContexts;
+	}
+
+	/** Returns the error files. */
+	public List<ModelStorageError> getErrorFiles() {
+		return errorFiles;
+	}
+}
-- 
GitLab