Author: DartPeng
Date: 2008-09-04 21:06:05 -0400 (Thu, 04 Sep 2008)
New Revision: 10085
Added:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/ConnectionPropertySection.java
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/SmooksGraphPropertyTypeMapper.java
Log:
Added:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/ConnectionPropertySection.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/ConnectionPropertySection.java
(rev 0)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/ConnectionPropertySection.java 2008-09-05
01:06:05 UTC (rev 10085)
@@ -0,0 +1,248 @@
+/**
+ *
+ */
+package org.jboss.tools.smooks.ui;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+import org.jboss.tools.smooks.ui.gef.model.AbstractStructuredDataConnectionModel;
+import org.jboss.tools.smooks.ui.gef.model.PropertyModel;
+
+/**
+ *
+ * @author Dart Peng<br>
+ * Date : Sep 4, 2008
+ */
+public class ConnectionPropertySection extends AbstractPropertySection {
+
+ private TableViewer tableViewer;
+
+ /**
+ *
+ */
+ public ConnectionPropertySection() {
+ }
+
+ @Override
+ public void createControls(Composite parent,
+ TabbedPropertySheetPage tabbedPropertySheetPage) {
+ super.createControls(parent, tabbedPropertySheetPage);
+ TabbedPropertySheetWidgetFactory factory = this.getWidgetFactory();
+
+ Section section = factory.createSection(parent, Section.TITLE_BAR);
+ section.setText("Mapping Properties");
+
+ Composite mainComposite = factory.createComposite(section);
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ mainComposite.setLayout(gridLayout);
+ tableViewer = new TableViewer(mainComposite);
+ tableViewer.setColumnProperties(new String[] { "name", "value" });
+ tableViewer.setCellEditors(new CellEditor[] { new
TextCellEditor(tableViewer.getTable()),
+ new TextCellEditor(tableViewer.getTable()) });
+ tableViewer.setCellModifier(new ICellModifier() {
+
+ public boolean canModify(Object element, String property) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public Object getValue(Object element, String property) {
+ if (element instanceof PropertyModel) {
+ if (property.equals("name"))
+ return ((PropertyModel) element).getName();
+ if (property.equals("value"))
+ return ((PropertyModel) element).getValue();
+ }
+ return element;
+ }
+
+ public void modify(Object element, String property, Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ });
+ tableViewer.getTable().setHeaderVisible(true);
+ tableViewer.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof AbstractStructuredDataConnectionModel) {
+ return ((AbstractStructuredDataConnectionModel) inputElement)
+ .getProperties().toArray();
+ }
+ return new Object[] {};
+ }
+
+ public void dispose() {
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+
+ }
+
+ });
+ // tableViewer.setLabelProvider(new PropertyLabelProvider());
+
+ // TableViewerColumn blankColumn = new TableViewerColumn(tableViewer,
+ // SWT.NONE);
+ // blankColumn.getColumn().setWidth(100);
+ // blankColumn.getColumn().setText(" ");
+ TableViewerColumn nameColumn = new TableViewerColumn(tableViewer,
+ SWT.NONE);
+ nameColumn.setLabelProvider(new CellLabelProvider() {
+
+ public void update(ViewerCell cell) {
+ Object obj = cell.getElement();
+ if (obj instanceof PropertyModel) {
+ cell.setText(((PropertyModel) obj).getName());
+ }
+ }
+
+ });
+ nameColumn.getColumn().setWidth(100);
+ nameColumn.getColumn().setText("Name");
+ TableViewerColumn valueColumn = new TableViewerColumn(tableViewer,
+ SWT.NONE);
+ valueColumn.getColumn().setWidth(100);
+ valueColumn.getColumn().setText("Value");
+ valueColumn.setLabelProvider(new CellLabelProvider() {
+
+ public void update(ViewerCell cell) {
+ Object obj = cell.getElement();
+ if (obj instanceof PropertyModel) {
+ cell.setText(((PropertyModel) obj).getValue());
+ }
+ }
+
+ });
+ section.setClient(mainComposite);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ tableViewer.getTable().setLayoutData(gd);
+
+ Composite buttonComposite = factory.createComposite(mainComposite);
+ gd = new GridData(GridData.FILL_VERTICAL);
+ buttonComposite.setLayoutData(gd);
+ GridLayout gl = new GridLayout();
+ buttonComposite.setLayout(gl);
+
+ Button button1 = factory.createButton(buttonComposite, "New ",
+ SWT.NONE);
+ button1.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ PropertyModel model = new PropertyModel();
+ model.setName("property");
+ model.setValue("value");
+
+ Object editPart = ((IStructuredSelection) getSelection())
+ .getFirstElement();
+ if (editPart instanceof EditPart) {
+ Object m = ((EditPart) editPart).getModel();
+ if (m instanceof AbstractStructuredDataConnectionModel) {
+ ((AbstractStructuredDataConnectionModel) m)
+ .getProperties().add(model);
+ refresh();
+ StructuredSelection selection = new StructuredSelection(
+ model);
+ tableViewer.setSelection(selection);
+ }
+ }
+ }
+
+ });
+ gd = new GridData(GridData.FILL_VERTICAL);
+ button1.setLayoutData(gd);
+
+ Button button2 = factory.createButton(buttonComposite, "Delete ",
+ SWT.NONE);
+ gd = new GridData(GridData.FILL_VERTICAL);
+ button2.setLayoutData(gd);
+
+ // Button button3 = factory.createButton(buttonComposite, "New ",
+ // SWT.NONE);
+ // gd = new GridData(GridData.FILL_VERTICAL);
+ // button3.setLayoutData(gd);
+
+ factory.paintBordersFor(parent);
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ IStructuredSelection selection = (IStructuredSelection) this
+ .getSelection();
+ Object obj = selection.getFirstElement();
+ if (obj == null)
+ return;
+ if (obj instanceof EditPart) {
+ Object model = ((EditPart) obj).getModel();
+ this.tableViewer.setInput(model);
+ }
+ }
+
+ @Override
+ public void setInput(IWorkbenchPart part, ISelection selection) {
+ super.setInput(part, selection);
+ }
+
+ private class PropertyLabelProvider extends LabelProvider implements
+ ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ if (element instanceof PropertyModel) {
+ return ((PropertyModel) element).getName();
+ }
+ return element.toString();
+
+ case 1:
+ if (element instanceof PropertyModel) {
+ return ((PropertyModel) element).getValue();
+ }
+ return element.toString();
+ }
+ return element.toString();
+ }
+
+ }
+
+}
Property changes on:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/ConnectionPropertySection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/SmooksGraphPropertyTypeMapper.java
===================================================================
---
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/SmooksGraphPropertyTypeMapper.java
(rev 0)
+++
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/SmooksGraphPropertyTypeMapper.java 2008-09-05
01:06:05 UTC (rev 10085)
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.ui;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.ui.views.properties.tabbed.ITypeMapper;
+
+/**
+ * @author Dart Peng<br>
+ * Date : Sep 4, 2008
+ */
+public class SmooksGraphPropertyTypeMapper implements ITypeMapper {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.views.properties.tabbed.ITypeMapper#mapType(java.lang.Object)
+ */
+ public Class mapType(Object object) {
+ if (object instanceof EditPart) {
+ Object model = ((EditPart) object).getModel();
+ if (model != null)
+ return model.getClass();
+ }
+ return null;
+ }
+
+}
Property changes on:
workspace/dart/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/ui/SmooksGraphPropertyTypeMapper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain