1 package net.sourceforge.phpeclipse.webbrowser.internal;
2 /**********************************************************************
3 * Copyright (c) 2003 IBM Corporation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Common Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/cpl-v10.html
10 * IBM - Initial API and implementation
11 **********************************************************************/
12 import java.util.List;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.viewers.*;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Item;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.swt.widgets.Table;
30 import org.eclipse.swt.widgets.TableColumn;
32 * Dialog to manage the favorites list.
34 public class OrganizeFavoritesDialog extends Dialog {
35 protected List favorites = WebBrowserPreference.getInternalWebBrowserFavorites();
37 public class FavoriteContentProvider implements IStructuredContentProvider {
38 public FavoriteContentProvider() {
42 public void dispose() { }
44 public Object[] getElements(Object inputElement) {
45 return favorites.toArray();
48 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
51 public class FavoriteLabelProvider implements ITableLabelProvider {
52 public FavoriteLabelProvider() {
56 public void addListener(ILabelProviderListener listener) { }
58 public void dispose() { }
60 public Image getColumnImage(Object element, int columnIndex) {
62 return ImageResource.getImage(ImageResource.IMG_FAVORITE);
66 public String getColumnText(Object element, int columnIndex) {
67 Favorite favorite = (Favorite) element;
69 return favorite.getName();
71 return favorite.getURL();
74 public boolean isLabelProperty(Object element, String property) {
78 public void removeListener(ILabelProviderListener listener) { }
82 * ManageFavoritesDialog constructor comment.
83 * @param parentShell org.eclipse.swt.widgets.Shell
86 public OrganizeFavoritesDialog(Shell parentShell) {
95 protected void configureShell(Shell newShell) {
96 super.configureShell(newShell);
97 newShell.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesTitle"));
103 protected Control createDialogArea(Composite parent) {
104 Composite composite = new Composite(parent, SWT.NONE);
105 GridLayout layout = new GridLayout();
106 layout.numColumns = 2;
107 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
108 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
109 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
110 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
111 composite.setLayout(layout);
112 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
113 composite.setFont(parent.getFont());
114 //WorkbenchHelp.setHelp(composite, ContextIds.TERMINATE_SERVER_DIALOG);
116 Label label = new Label(composite, SWT.NONE);
117 label.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesMessage"));
118 GridData data = new GridData();
119 data.horizontalSpan = 2;
120 label.setLayoutData(data);
122 final Table table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
123 data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
124 data.widthHint = 300;
125 data.heightHint = 150;
126 table.setLayoutData(data);
127 table.setLinesVisible(true);
129 TableLayout tableLayout = new TableLayout();
130 table.setLayout(tableLayout);
131 table.setHeaderVisible(true);
133 tableLayout.addColumnData(new ColumnWeightData(5, 50, true));
134 TableColumn col = new TableColumn(table, SWT.NONE);
135 col.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesName"));
137 tableLayout.addColumnData(new ColumnWeightData(6, 60, true));
138 col = new TableColumn(table, SWT.NONE);
139 col.setText(WebBrowserUIPlugin.getResource("%dialogOrganizeFavoritesURL"));
140 table.setLayout(tableLayout);
142 final TableViewer tableViewer = new TableViewer(table);
143 tableViewer.setContentProvider(new FavoriteContentProvider());
144 tableViewer.setLabelProvider(new FavoriteLabelProvider());
145 tableViewer.setInput("root");
146 tableViewer.setColumnProperties(new String[] {"name", "url"});
148 tableViewer.setCellEditors(new CellEditor[] {new TextCellEditor(table), new TextCellEditor(table)});
150 ICellModifier cellModifier = new ICellModifier() {
151 public Object getValue(Object element, String property) {
152 Favorite f = (Favorite) element;
153 if ("name".equals(property))
159 public boolean canModify(Object element, String property) {
163 public void modify(Object element, String property, Object value) {
164 if (element instanceof Item)
165 element = ((Item) element).getData();
168 Favorite f = (Favorite) element;
169 String s = (String) value;
170 if ("name".equals(property))
174 tableViewer.refresh(f);
175 } catch (Exception ex) {
176 ex.printStackTrace();
180 tableViewer.setCellModifier(cellModifier);
182 final Button remove = SWTUtil.createButton(composite, WebBrowserUIPlugin.getResource("%remove"));
183 remove.setEnabled(false);
185 tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
186 public void selectionChanged(SelectionChangedEvent event) {
187 remove.setEnabled(!event.getSelection().isEmpty());
191 remove.addSelectionListener(new SelectionAdapter() {
192 public void widgetSelected(SelectionEvent e) {
193 int index = table.getSelectionIndex();
194 if (index < 0 || index >= favorites.size())
197 tableViewer.remove(favorites.get(index));
198 favorites.remove(index);
202 Dialog.applyDialogFont(composite);
207 protected void okPressed() {
208 WebBrowserPreference.setInternalWebBrowserFavorites(favorites);