This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ParaViewPreferencePage.java
167 lines (145 loc) · 5.62 KB
/
ParaViewPreferencePage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
* Copyright (c) 2015- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are 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:
* Initial API and implementation and/or initial documentation -
* Jordan Deyton
*******************************************************************************/
package org.eclipse.ice.viz.service.paraview;
import java.util.List;
import org.eclipse.ice.viz.service.AbstractVizPreferencePage;
import org.eclipse.ice.viz.service.connections.ConnectionTable;
import org.eclipse.ice.viz.service.connections.IKeyChangeListener;
import org.eclipse.ice.viz.service.preferences.CustomScopedPreferenceStore;
import org.eclipse.ice.viz.service.preferences.DynamicComboFieldEditor;
import org.eclipse.ice.viz.service.preferences.TableComponentComposite;
import org.eclipse.ice.viz.service.preferences.TableComponentPreferenceAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
/**
* This class provides a preference page for the ParaView visualization service.
*
* @author Jordan Deyton
*
*/
public class ParaViewPreferencePage extends AbstractVizPreferencePage {
/**
* The {@code ConnectionManager} used by this preference page. It is
* represented by a table on the page.
*/
private final ConnectionTable connectionManager = new ConnectionTable();
/**
* The default constructor.
*/
public ParaViewPreferencePage() {
super(GRID);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
@Override
public void init(IWorkbench workbench) {
setDescription("ParaView Connection Preferences");
// Read the table of connections stored in the preferences into the
// ConnectionManager.
TableComponentPreferenceAdapter adapter = new TableComponentPreferenceAdapter();
adapter.toTableComponent(
(CustomScopedPreferenceStore) getPreferenceStore(),
connectionManager);
return;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors
* ()
*/
@Override
protected void createFieldEditors() {
Composite parent = getFieldEditorParent();
// Create a new DynamicComboFieldEditor for the default connection. The
// default connection should only be selected from the list of
// connections from the connection table.
final DynamicComboFieldEditor defaultConnection;
defaultConnection = new DynamicComboFieldEditor("defaultConnection",
"Default Connection", parent,
connectionManager.getConnectionNames());
addField(defaultConnection);
// Add a key change listener so that we can refresh the values in the
// default connection field editor when necessary.
connectionManager.addKeyChangeListener(new IKeyChangeListener() {
@Override
public void keyChanged(String oldKey, String newKey) {
// Get the current value for the default connection.
String value = defaultConnection.getValue();
// Update the default connection Combo's allowed values.
List<String> names = connectionManager.getConnectionNames();
defaultConnection.setAllowedValues(names);
// If the selected connection's name was changed, make sure it
// is still the default connection.
if (oldKey != null && newKey != null && oldKey.equals(value)) {
defaultConnection.setValue(newKey);
}
return;
}
});
return;
}
/**
* Overrides the default behavior to provide a connection table below the
* default connection preference {@code FieldEditor}s.
*/
@Override
protected Control createContents(Composite parent) {
// Create the default layout initially. This also gives us the return
// value.
Control control = super.createContents(parent);
// Get the created parent Composite for all FieldEditors. We need its
// layout to make sure the connection table spans all horizontal space.
Composite container = getFieldEditorParent();
GridLayout gridLayout = (GridLayout) container.getLayout();
// If there are no field editors, the number of columns is 0, which
// prevents the table from appearing. We need to update the number of
// columns in this case.
if (gridLayout.numColumns == 0) {
gridLayout.numColumns = 1;
}
// Create a ConnectionComposite to show all of the cached connection
// preferences.
TableComponentComposite connections = new TableComponentComposite(
container, SWT.NONE);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true,
gridLayout.numColumns, 1);
connections.setLayoutData(gridData);
// Set the custom Composite's TableComponent to fill the table.
connections.setTableComponent(connectionManager);
return control;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk()
*/
@Override
public boolean performOk() {
boolean ok = super.performOk();
// Write the table of connections stored in the ConnectionManager into
// the preference store.
TableComponentPreferenceAdapter adapter = new TableComponentPreferenceAdapter();
adapter.toPreferences(connectionManager,
(CustomScopedPreferenceStore) getPreferenceStore());
return ok;
}
}