1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
13 * Created on 13.10.2005
14 * @author Toni Kalajainen
16 package org.simantics.utils.ui.workbench.dialogs;
18 import java.util.List;
21 import org.eclipse.jface.viewers.IStructuredContentProvider;
22 import org.eclipse.jface.viewers.TableViewer;
23 import org.eclipse.jface.viewers.Viewer;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.swt.widgets.Table;
29 import org.eclipse.swt.widgets.TableColumn;
30 import org.eclipse.ui.dialogs.ListDialog;
31 import org.simantics.utils.ui.jface.StringListLabelProvider;
32 import org.simantics.utils.ui.workbench.ui.TableColumnSorter;
37 * PropertyDialog is a dialog window popup for properties (key, value pairs)
40 public class PropertyDialog extends ListDialog {
42 public final static String KEY_COLUMN_NAME = "Key";
43 public final static String VALUE_COLUMN_NAME = "Value";
45 protected List<String[]>data;
46 protected StringListLabelProvider labelProvider;
48 public PropertyDialog(Shell parent) {
51 this.setContentProvider(new IStructuredContentProvider() {
52 public Object[] getElements(Object inputElement) {
53 List<?> lines = (List<?>) inputElement;
54 return lines.toArray(new String[0][0]);
56 public void dispose() {
58 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
63 public int columnNameToColumn(String name) {
64 if (name.equals(KEY_COLUMN_NAME)) return 0;
65 if (name.equals(VALUE_COLUMN_NAME)) return 1;
70 protected Control createDialogArea(Composite container) {
71 Control composite = super.createDialogArea(container);
72 TableViewer viewer = getTableViewer();
73 Table table = viewer.getTable();
75 //viewer.setUseHashlookup(true);
76 table.setHeaderVisible(true);
77 table.setLinesVisible(true);
81 final TableColumn tableColumn = new TableColumn(table, table.getStyle(), 0);
82 tableColumn.setWidth(100);
83 tableColumn.setText(KEY_COLUMN_NAME);
85 final TableColumn tableColumn_2 = new TableColumn(table, table.getStyle(), 1);
86 tableColumn_2.setWidth(190);
87 tableColumn_2.setText(VALUE_COLUMN_NAME);
89 // Dialog area is created when dialog.open is called
90 // which is after input has been set
91 // Therefore there columns have not been created at the time
92 // of setting input object before columns have been set.
93 // Re-setting input forces to read columns
94 viewer.setInput( getTableViewer().getInput() );
95 viewer.setColumnProperties(new String[] {KEY_COLUMN_NAME, VALUE_COLUMN_NAME});
97 TableColumnSorter.attachTableColumnSorter( viewer );
102 public void setInput(String lines[][]) {
103 labelProvider = new StringListLabelProvider(lines);
104 this.setLabelProvider( labelProvider );
105 data = labelProvider.getData();
106 super.setInput(data);
110 protected int getTableStyle()
112 return SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION;
115 public void setInput(Map<String, String> properties) {
116 String lines[][] = new String[properties.size()][];
118 for (String key : properties.keySet()) {
119 String line[] = new String[] {key, properties.get(key)};