X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fjava%2Feclipse-plugin%2FClientControllerPlugin%2Fsrc%2Foic%2Fsimulator%2Fclientcontroller%2Fview%2Fdialogs%2FPostRequestDialog.java;h=53ff50eef562d99fc44f213ea485d2d0bb183307;hb=b2b47c415c84402c1289ff0cae28cae46a72a55f;hp=934cbb3594786b27f2c462683759cbf5bf473a82;hpb=7ae4722f8ce34059a59a179c113cad5e8a2d05b9;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java index 934cbb3..53ff50e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java @@ -16,61 +16,66 @@ package oic.simulator.clientcontroller.view.dialogs; -import java.util.Iterator; -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.utils.Constants; - import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; 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.ComboBoxCellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StyledCellLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; +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.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; 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 java.util.HashMap; +import java.util.Map; + +import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.SimulatorResourceAttribute; + +import oic.simulator.clientcontroller.Activator; +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; /** * This dialog is used for generating a POST request. */ public class PostRequestDialog extends TitleAreaDialog { - private TableViewer attTblViewer; + private TreeViewer attViewer; + private Combo ifTypesCmb; + + private String ifType; + + private Map ifTypes; + + private AttributeEditingSupport attributeEditor; - private final String[] attTblHeaders = { "Name", "Value", - "Select" }; - private final Integer[] attTblColWidth = { 200, 200, 50 }; + private ResourceRepresentation updatedRepresentation; - private List modelList = null; + private final String[] attTblHeaders = { "Name", "Value", + "Select" }; + private final Integer[] attTblColWidth = { 200, 200, 50 }; - public PostRequestDialog(Shell parentShell, - List modelList) { + public PostRequestDialog(Shell parentShell) { super(parentShell); - this.modelList = modelList; - resourceManager = Activator.getDefault().getResourceManager(); } @Override @@ -83,277 +88,255 @@ public class PostRequestDialog extends TitleAreaDialog { @Override protected Control createDialogArea(Composite parent) { Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(1, false); + + Group paramsGrp = new Group(compLayout, SWT.NONE); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + paramsGrp.setLayoutData(gd); + GridLayout layout = new GridLayout(2, false); layout.verticalSpacing = 10; layout.marginTop = 10; - container.setLayout(layout); + paramsGrp.setLayout(layout); - createTableViewer(container); + Label ifTypeLbl = new Label(paramsGrp, SWT.NONE); + ifTypeLbl.setText("Interface Type"); - attTblViewer.setInput(modelList.toArray()); + ifTypesCmb = new Combo(paramsGrp, SWT.NULL); + gd = new GridData(); + gd.grabExcessHorizontalSpace = true; + gd.horizontalAlignment = SWT.FILL; + ifTypesCmb.setLayoutData(gd); + ifTypesCmb.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + ifType = ifTypesCmb.getText(); + } + }); - return compLayout; - } + // Set the interface types. + Map ifTypes = Utility.getResourceInterfaces(); + if (null != ifTypes && !ifTypes.isEmpty()) { + this.ifTypes = new HashMap(); + String key; + for (Map.Entry entry : ifTypes.entrySet()) { + key = entry.getValue() + " (" + entry.getKey() + ")"; + this.ifTypes.put(key, entry.getKey()); + ifTypesCmb.add(key); + } + } - private void createTableViewer(Composite parent) { - attTblViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + Composite container = new Composite(compLayout, SWT.NONE); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + layout = new GridLayout(1, false); + layout.verticalSpacing = 10; + layout.marginTop = 10; + container.setLayout(layout); - createAttributeColumns(attTblViewer); + createTreeViewer(container); - // 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); + RemoteResource resource = Activator.getDefault().getResourceManager() + .getCurrentResourceInSelection(); - attTblViewer.setContentProvider(new AttributeContentProvider()); - } + updatedRepresentation = new ResourceRepresentation( + resource.getResourceModelRef()); - public void createAttributeColumns(TableViewer tableViewer) { + attViewer.setInput(updatedRepresentation); - // attributeEditor = new AttributeEditingSupport(); + attViewer.expandAll(); - 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()); - } - } - }); + return compLayout; + } - attValue.setEditingSupport(new AttributeValueEditor(attTblViewer)); + 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); - 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 CCombo comboBox; + public Object[] getChildren(Object attribute) { + if (attribute instanceof AttributeElement) { + return ((AttributeElement) attribute).getChildren().values() + .toArray(); + } - public AttributeValueEditor(TableViewer viewer) { - super(viewer); - this.viewer = viewer; + return new Object[0]; } @Override - protected boolean canEdit(Object arg0) { - return true; + public Object getParent(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).getParent(); + return null; } @Override - protected CellEditor getCellEditor(Object element) { - PutPostAttributeModel attributeInSelection = (PutPostAttributeModel) element; - - String values[] = null; - List valueSet = attributeInSelection.getValues(); - values = convertListToStringArray(valueSet); - - ComboBoxCellEditor comboEditor = new ComboBoxCellEditor( - viewer.getTable(), values); - comboBox = (CCombo) comboEditor.getControl(); - if (null != comboBox) { - comboBox.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - IStructuredSelection selection = (IStructuredSelection) AttributeValueEditor.this.viewer - .getSelection(); - PutPostAttributeModel att = (PutPostAttributeModel) selection - .getFirstElement(); - if (null == att) { - return; - } - String newValue = comboBox.getText(); - if (null != newValue && !newValue.isEmpty()) { - att.setModified(true); - } else { - att.setModified(false); - } - AttributeValueEditor.this.viewer.update(att, null); - } - }); - } - return comboEditor; + public boolean hasChildren(Object attribute) { + if (attribute instanceof AttributeElement) + return ((AttributeElement) attribute).hasChildren(); + return false; } @Override - protected Object getValue(Object element) { - int indexOfItem = 0; - PutPostAttributeModel att = (PutPostAttributeModel) element; - String valueString = att.getAttValue(); - List valueSet = att.getValues(); - if (null != valueSet) { - indexOfItem = valueSet.indexOf(valueString); + public Object[] getElements(Object resourceModel) { + if (resourceModel instanceof ResourceRepresentation) { + return ((ResourceRepresentation) resourceModel).getAttributes() + .values().toArray(); } - if (indexOfItem == -1) { - indexOfItem = 0; - } - return indexOfItem; - } - @Override - protected void setValue(Object element, Object value) { - PutPostAttributeModel att = (PutPostAttributeModel) element; - int index; - try { - index = Integer.parseInt(String.valueOf(value)); - } catch (NumberFormatException nfe) { - index = -1; - } - String newValue; - if (index == -1) { - newValue = comboBox.getText(); - att.prependNewValue(newValue); - } else { - newValue = att.getValues().get(index); - } - att.setAttValue(newValue); - viewer.update(element, null); - } - - public String[] convertListToStringArray(List valueList) { - String[] strArr; - if (null != valueList && valueList.size() > 0) { - strArr = valueList.toArray(new String[1]); - } else { - strArr = new String[1]; - } - return strArr; + 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 void okPressed() { - String value; - PutPostAttributeModel attModel; - Iterator itr; - itr = modelList.iterator(); - while (itr.hasNext()) { - attModel = itr.next(); - if (null == attModel) { - return; - } - value = attModel.getAttValue(); - if (null == value || value.isEmpty()) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Empty value", "Attribute value should not be empty."); - return; - } + 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; + } + + public String getIfType() { + if (ifTypes.containsKey(ifType)) { + return ifTypes.get(ifType); } - close(); + return ifType; } }