package oic.simulator.clientcontroller.view.dialogs;
-import java.util.List;
-
import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.manager.ResourceManager;
-import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
+import oic.simulator.clientcontroller.remoteresource.AttributeElement;
+import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
+import oic.simulator.clientcontroller.view.AttributeEditingSupport;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.SimulatorResourceAttribute;
/**
* This dialog is used for generating a POST request.
*/
public class PostRequestDialog extends TitleAreaDialog {
- private TableViewer attTblViewer;
+ private TreeViewer attViewer;
- private final String[] attTblHeaders = { "Name", "Value",
- "Select" };
- private final Integer[] attTblColWidth = { 200, 200, 50 };
+ private AttributeEditingSupport attributeEditor;
- private ResourceManager resourceManager;
+ private ResourceRepresentation updatedRepresentation;
- private List<PutPostAttributeModel> modelList = null;
+ private final String[] attTblHeaders = { "Name", "Value",
+ "Select" };
+ private final Integer[] attTblColWidth = { 200, 200, 50 };
- public PostRequestDialog(Shell parentShell,
- List<PutPostAttributeModel> modelList) {
+ public PostRequestDialog(Shell parentShell) {
super(parentShell);
- this.modelList = modelList;
- resourceManager = Activator.getDefault().getResourceManager();
}
@Override
layout.marginTop = 10;
container.setLayout(layout);
- createTableViewer(container);
+ createTreeViewer(container);
- attTblViewer.setInput(modelList.toArray());
+ RemoteResource resource = Activator.getDefault().getResourceManager()
+ .getCurrentResourceInSelection();
- return compLayout;
- }
+ updatedRepresentation = new ResourceRepresentation(
+ resource.getResourceModelRef());
- private void createTableViewer(Composite parent) {
- attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
- | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ attViewer.setInput(updatedRepresentation);
- createAttributeColumns(attTblViewer);
-
- // make lines and header visible
- Table table = attTblViewer.getTable();
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- attTblViewer.setContentProvider(new AttributeContentProvider());
+ return compLayout;
}
- public void createAttributeColumns(TableViewer tableViewer) {
+ private void createTreeViewer(Composite parent) {
+ Tree addressTree = new Tree(parent, SWT.SINGLE | SWT.BORDER
+ | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
+ addressTree.setHeaderVisible(true);
- // attributeEditor = new AttributeEditingSupport();
-
- TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
- attName.getColumn().setWidth(attTblColWidth[0]);
- attName.getColumn().setText(attTblHeaders[0]);
- attName.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttName());
- }
- }
- });
-
- TableViewerColumn attValue = new TableViewerColumn(tableViewer,
- SWT.NONE);
- attValue.getColumn().setWidth(attTblColWidth[1]);
- attValue.getColumn().setText(attTblHeaders[1]);
- attValue.setLabelProvider(new StyledCellLabelProvider() {
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- if (element instanceof PutPostAttributeModel) {
- PutPostAttributeModel entry = (PutPostAttributeModel) element;
- cell.setText(entry.getAttValue());
- }
- }
- });
- attValue.setEditingSupport(new AttributeValueEditor(attTblViewer));
-
- TableViewerColumn updateColumn = new TableViewerColumn(tableViewer,
- SWT.NONE);
- updateColumn.getColumn().setWidth(attTblColWidth[2]);
- updateColumn.getColumn().setText(attTblHeaders[2]);
- updateColumn.setLabelProvider(new ColumnLabelProvider() {
- @Override
- public String getText(Object element) {
- return "";
- }
+ attViewer = new TreeViewer(addressTree);
- @Override
- public Image getImage(Object element) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- if (model.isModified()) {
- return Activator.getDefault().getImageRegistry()
- .get(Constants.CHECKED);
- }
- return Activator.getDefault().getImageRegistry()
- .get(Constants.UNCHECKED);
- }
- });
- updateColumn.setEditingSupport(new UpdateEditor(attTblViewer));
- }
+ createAttributeColumns(attViewer);
- @Override
- protected boolean isResizable() {
- return true;
- }
+ // make lines and header visible
+ Tree tree = attViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
- @Override
- public boolean isHelpAvailable() {
- return false;
+ attViewer.setContentProvider(new AttributeContentProvider());
+ attViewer.setLabelProvider(new AttributeLabelProvider());
}
- @Override
- protected Button createButton(Composite parent, int id, String label,
- boolean defaultButton) {
- if (id == IDialogConstants.OK_ID) {
- label = "POST";
- }
- return super.createButton(parent, id, label, defaultButton);
+ public void createAttributeColumns(TreeViewer viewer) {
+ Tree tree = viewer.getTree();
+
+ attributeEditor = new AttributeEditingSupport();
+
+ TreeColumn attName = new TreeColumn(tree, SWT.NONE);
+ attName.setWidth(attTblColWidth[0]);
+ attName.setText(attTblHeaders[0]);
+
+ TreeColumn attValue = new TreeColumn(tree, SWT.NONE);
+ attValue.setWidth(attTblColWidth[1]);
+ attValue.setText(attTblHeaders[1]);
+ TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer,
+ attValue);
+ attValueVwrCol.setEditingSupport(attributeEditor
+ .createAttributeValueEditor(attViewer, this));
+
+ TreeColumn updateColumn = new TreeColumn(tree, SWT.NONE);
+ updateColumn.setWidth(attTblColWidth[2]);
+ updateColumn.setText(attTblHeaders[2]);
+ TreeViewerColumn updateVwrCol = new TreeViewerColumn(attViewer,
+ updateColumn);
+ updateVwrCol.setEditingSupport(attributeEditor
+ .createAutomationEditor(attViewer));
}
- class AttributeContentProvider implements IStructuredContentProvider {
+ class AttributeContentProvider implements ITreeContentProvider {
@Override
public void dispose() {
}
@Override
- public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ public void inputChanged(Viewer viewer, Object oldAttribute,
+ Object newAttribute) {
}
@Override
- public Object[] getElements(Object element) {
- return (Object[]) element;
- }
-
- }
-
- class AttributeValueEditor extends EditingSupport {
- private final TableViewer viewer;
- private final CellEditor editor;
-
- public AttributeValueEditor(TableViewer viewer) {
- super(viewer);
- this.viewer = viewer;
- editor = new TextCellEditor(viewer.getTable());
- }
+ public Object[] getChildren(Object attribute) {
+ if (attribute instanceof AttributeElement) {
+ return ((AttributeElement) attribute).getChildren().values()
+ .toArray();
+ }
- @Override
- protected boolean canEdit(Object arg0) {
- return true;
+ return new Object[0];
}
@Override
- protected CellEditor getCellEditor(Object element) {
- return editor;
+ public Object getParent(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).getParent();
+ return null;
}
@Override
- protected Object getValue(Object element) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- return model.getAttValue();
+ public boolean hasChildren(Object attribute) {
+ if (attribute instanceof AttributeElement)
+ return ((AttributeElement) attribute).hasChildren();
+ return false;
}
@Override
- protected void setValue(Object element, Object value) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- // Compare the actual value and the new value
- // If there is a change, then its corresponding check box should be
- // checked.
- String newValue = String.valueOf(value);
- String actualValue = resourceManager.getAttributeValue(
- resourceManager.getCurrentResourceInSelection(),
- model.getAttName());
- if (newValue.equals(actualValue)) {
- model.setModified(false);
- } else {
- model.setModified(true);
+ public Object[] getElements(Object resourceModel) {
+ if (resourceModel instanceof ResourceRepresentation) {
+ return ((ResourceRepresentation) resourceModel).getAttributes()
+ .values().toArray();
}
- model.setAttValue(newValue);
- viewer.update(element, null);
+
+ return new Object[0];
}
}
- class UpdateEditor extends EditingSupport {
+ class AttributeLabelProvider implements ITableLabelProvider {
- private final TableViewer viewer;
+ @Override
+ public void addListener(ILabelProviderListener arg0) {
+ }
- public UpdateEditor(TableViewer viewer) {
- super(viewer);
- this.viewer = viewer;
+ @Override
+ public void dispose() {
}
@Override
- protected boolean canEdit(Object arg0) {
- return true;
+ public boolean isLabelProperty(Object arg0, String arg1) {
+ return false;
}
@Override
- protected CellEditor getCellEditor(Object element) {
- return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+ public void removeListener(ILabelProviderListener arg0) {
+
}
@Override
- protected Object getValue(Object element) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- return model.isModified();
+ public Image getColumnImage(Object element, int col) {
+ if (col == 2) {
+ if (element instanceof AttributeElement) {
+
+ AttributeElement attrElement = (AttributeElement) element;
+ if (attrElement.isPostSupported()) {
+ if (attrElement.getPostState()) {
+ return Activator.getDefault().getImageRegistry()
+ .get(Constants.CHECKED);
+ } else {
+ return Activator.getDefault().getImageRegistry()
+ .get(Constants.UNCHECKED);
+ }
+ }
+ }
+ }
+
+ return null;
}
@Override
- protected void setValue(Object element, Object value) {
- PutPostAttributeModel model = (PutPostAttributeModel) element;
- boolean status = (boolean) value;
- model.setModified(status);
- viewer.update(element, null);
+ public String getColumnText(Object element, int column) {
+ if (element instanceof AttributeElement) {
+ AttributeElement attrElement = (AttributeElement) element;
+ switch (column) {
+ case 0: // Attribute name column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+ return attribute.name();
+ }
+
+ case 1: // Attribute value column
+ {
+ SimulatorResourceAttribute attribute = attrElement
+ .getSimulatorResourceAttribute();
+
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
+ return Utility.getAttributeValueAsString(attribute
+ .value());
+ return null;
+ }
+
+ case 2: {
+ return "";
+ }
+ }
+ }
+ return null;
}
}
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+
+ @Override
+ protected Button createButton(Composite parent, int id, String label,
+ boolean defaultButton) {
+ if (id == IDialogConstants.OK_ID) {
+ label = "POST";
+ }
+ return super.createButton(parent, id, label, defaultButton);
+ }
+
+ public ResourceRepresentation getUpdatedRepresentation() {
+ return updatedRepresentation;
+ }
}