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
/
ElementSourceDialog.java
118 lines (102 loc) · 3.01 KB
/
ElementSourceDialog.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
/*******************************************************************************
* Copyright (c) 2014 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 -
* Jay Jay Billings
*******************************************************************************/
package org.eclipse.ice.client.widgets;
import org.eclipse.ice.datastructures.ICEObject.IElementSource;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.swt.DefaultEventTableViewer;
/**
* This class is a JFace Dialog for rendering IElementSources that are used by
* ListComponents.
*
* Only single selections are supported.
*
* @author Jay Jay Billings
*
*/
public class ElementSourceDialog<T> extends Dialog {
/**
* The source that should be drawn
*/
private IElementSource<T> source;
/**
* The SWT table that shows the list
*/
private Table listTable;
/**
* The selection made by the user or null if the dialog was closed.
*/
private T selection;
/**
* The list of elements rendered in the table
*/
private EventList<T> elements;
/**
* The constructor
*
* @param parentShell
* The shell in which the dialog should be drawn
* @param source
* The IElementSource that should be drawn
*/
public ElementSourceDialog(Shell parentShell,
IElementSource<T> elementSource) {
super(parentShell);
source = elementSource;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
* .Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
// Create the table to hold the ListComponent.
listTable = new Table(parent, SWT.FLAT);
elements = source.getElements();
DefaultEventTableViewer listTableViewer = new DefaultEventTableViewer(
elements, listTable, source.getTableFormat());
listTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
1));
return comp;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
// Set the selection if the OK button was pressed
int index = listTable.getSelectionIndex();
selection = elements.get(index);
super.okPressed();
}
/**
* This operation returns the selection made in the dialog.
*
* @return The selection. If multiple items were selected, only the first is
* returned.
*/
public T getSelection() {
return selection;
}
}