2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package oic.simulator.serviceprovider.view;
19 import java.util.List;
21 import oic.simulator.serviceprovider.Activator;
22 import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
23 import oic.simulator.serviceprovider.manager.ResourceManager;
24 import oic.simulator.serviceprovider.resource.MetaProperty;
25 import oic.simulator.serviceprovider.resource.SimulatorResource;
27 import org.eclipse.jface.viewers.ColumnLabelProvider;
28 import org.eclipse.jface.viewers.IStructuredContentProvider;
29 import org.eclipse.jface.viewers.TableViewer;
30 import org.eclipse.jface.viewers.TableViewerColumn;
31 import org.eclipse.jface.viewers.Viewer;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Display;
37 import org.eclipse.swt.widgets.Table;
38 import org.eclipse.ui.part.ViewPart;
41 * This class manages and shows the meta properties view in the perspective.
43 public class MetaPropertiesView extends ViewPart {
45 public static final String VIEW_ID = "oic.simulator.serviceprovider.view.metaproperties";
47 private TableViewer tableViewer;
49 private final String[] columnHeaders = { "Property",
52 private final Integer[] columnWidth = { 150, 150 };
54 private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
56 private ResourceManager resourceManagerRef;
58 public MetaPropertiesView() {
60 resourceManagerRef = Activator.getDefault().getResourceManager();
62 resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
65 public void onResourceSelectionChange() {
66 Display.getDefault().asyncExec(new Runnable() {
70 if (null != tableViewer) {
71 updateViewer(getData());
80 public void createPartControl(Composite parent) {
81 parent.setLayout(new GridLayout(1, false));
83 tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
84 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
86 createColumns(tableViewer);
88 // Make lines and header visible
89 final Table table = tableViewer.getTable();
90 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
91 table.setHeaderVisible(true);
92 table.setLinesVisible(true);
94 tableViewer.setContentProvider(new PropertycontentProvider());
96 addManagerListeners();
98 // Check whether there is any resource selected already
99 List<MetaProperty> propertyList = getData();
100 if (null != propertyList) {
101 updateViewer(propertyList);
106 private List<MetaProperty> getData() {
107 SimulatorResource resourceInSelection = resourceManagerRef
108 .getCurrentResourceInSelection();
109 if (null != resourceInSelection) {
110 List<MetaProperty> metaPropertyList = resourceManagerRef
111 .getMetaProperties(resourceInSelection);
112 return metaPropertyList;
118 private void updateViewer(List<MetaProperty> metaPropertyList) {
119 if (null != tableViewer) {
120 Table tbl = tableViewer.getTable();
121 if (null != metaPropertyList) {
122 tableViewer.setInput(metaPropertyList.toArray());
123 if (!tbl.isDisposed()) {
124 tbl.setLinesVisible(true);
127 if (!tbl.isDisposed()) {
129 tbl.setLinesVisible(false);
135 public void createColumns(TableViewer tableViewer) {
136 TableViewerColumn propName = new TableViewerColumn(tableViewer,
138 propName.getColumn().setWidth(columnWidth[0]);
139 propName.getColumn().setText(columnHeaders[0]);
140 propName.setLabelProvider(new ColumnLabelProvider() {
142 public String getText(Object element) {
143 MetaProperty prop = (MetaProperty) element;
145 return prop.getPropName();
152 TableViewerColumn propValue = new TableViewerColumn(tableViewer,
154 propValue.getColumn().setWidth(columnWidth[1]);
155 propValue.getColumn().setText(columnHeaders[1]);
156 propValue.setLabelProvider(new ColumnLabelProvider() {
158 public String getText(Object element) {
159 MetaProperty prop = (MetaProperty) element;
161 return prop.getPropValue();
169 private void addManagerListeners() {
171 .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
174 class PropertycontentProvider implements IStructuredContentProvider {
177 public void dispose() {
181 public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
185 public Object[] getElements(Object element) {
186 return (Object[]) element;
192 public void dispose() {
193 // Unregister the listener
194 if (null != resourceSelectionChangedListener) {
196 .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
202 public void setFocus() {