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