1 package com.quantum.ui.dialog;
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
6 import com.quantum.Messages;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.BookmarkCollection;
10 import org.eclipse.jface.dialogs.Dialog;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Event;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.List;
19 import org.eclipse.swt.widgets.Listener;
20 import org.eclipse.swt.widgets.Shell;
25 public class BookmarkSelectionDialog extends Dialog {
28 private String selection = null;
29 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
34 public BookmarkSelectionDialog(Shell parentShell) {
36 int style = getShellStyle() | SWT.TITLE;
40 protected void configureShell(Shell shell) {
41 super.configureShell(shell);
42 shell.setText(Messages.getString("BookmarkSelectionDialog.title"));
46 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
48 protected Control createDialogArea(Composite parent) {
50 Composite composite = new Composite(parent, 0);
51 GridLayout layout = new GridLayout();
52 composite.setLayout(layout);
53 layout.numColumns = 1;
54 layout.verticalSpacing = 1;
56 Label label = new Label(composite, SWT.NULL);
57 label.setText(Messages.getString("BookmarkSelectionDialog.text"));
59 this.list = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
60 Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
62 for (int i = 0, length = (bookmarks == null) ? 0 : bookmarks.length; i < length; i++) {
63 this.list.add(bookmarks[i].getName());
66 setSelection(bookmarks[i].getName());
70 final List list = this.list;
71 list.addListener(SWT.Selection, new Listener() {
72 public void handleEvent (Event event) {
73 String[] selections = list.getSelection();
74 if (selections != null && selections.length > 0) {
75 BookmarkSelectionDialog.this.setSelection(selections[0]);
80 GridData full = new GridData();
81 full.horizontalAlignment = GridData.FILL;
82 full.verticalAlignment = GridData.FILL;
83 full.heightHint = convertHeightInCharsToPixels(3);
84 this.list.setLayoutData(full);
92 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
93 this.propertyChangeSupport.addPropertyChangeListener(listener);
99 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
100 this.propertyChangeSupport.removePropertyChangeListener(listener);
103 private void setSelection(String selection) {
104 String original = this.selection;
105 if (this.selection == null || !this.selection.equals(selection)) {
106 this.selection = selection;
107 this.propertyChangeSupport.firePropertyChange("selection", original, this.selection);