1 package net.sourceforge.phpeclipse.webbrowser.internal;
3 /**********************************************************************
4 * Copyright (c) 2003 IBM Corporation and others.
5 * All rights reserved. � This program and the accompanying materials
6 * are made available under the terms of the Common Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/cpl-v10.html
11 * IBM - Initial API and implementation
12 **********************************************************************/
13 import java.util.List;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.viewers.CellEditor;
18 import org.eclipse.jface.viewers.ColumnWeightData;
19 import org.eclipse.jface.viewers.ICellModifier;
20 import org.eclipse.jface.viewers.ILabelProviderListener;
21 import org.eclipse.jface.viewers.ISelectionChangedListener;
22 import org.eclipse.jface.viewers.IStructuredContentProvider;
23 import org.eclipse.jface.viewers.ITableLabelProvider;
24 import org.eclipse.jface.viewers.SelectionChangedEvent;
25 import org.eclipse.jface.viewers.TableLayout;
26 import org.eclipse.jface.viewers.TableViewer;
27 import org.eclipse.jface.viewers.TextCellEditor;
28 import org.eclipse.jface.viewers.Viewer;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.events.SelectionAdapter;
31 import org.eclipse.swt.events.SelectionEvent;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Item;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Shell;
41 import org.eclipse.swt.widgets.Table;
42 import org.eclipse.swt.widgets.TableColumn;
45 * Dialog to manage the favorites list.
47 public class OrganizeFavoritesDialog extends Dialog {
48 protected List favorites = WebBrowserPreference
49 .getInternalWebBrowserFavorites();
51 public class FavoriteContentProvider implements IStructuredContentProvider {
52 public FavoriteContentProvider() {
56 public void dispose() {
59 public Object[] getElements(Object inputElement) {
60 return favorites.toArray();
63 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
67 public class FavoriteLabelProvider implements ITableLabelProvider {
68 public FavoriteLabelProvider() {
72 public void addListener(ILabelProviderListener listener) {
75 public void dispose() {
78 public Image getColumnImage(Object element, int columnIndex) {
80 return ImageResource.getImage(ImageResource.IMG_FAVORITE);
84 public String getColumnText(Object element, int columnIndex) {
85 Favorite favorite = (Favorite) element;
87 return favorite.getName();
89 return favorite.getURL();
92 public boolean isLabelProperty(Object element, String property) {
96 public void removeListener(ILabelProviderListener listener) {
101 * ManageFavoritesDialog constructor comment.
104 * org.eclipse.swt.widgets.Shell @
106 public OrganizeFavoritesDialog(Shell parentShell) {
109 setBlockOnOpen(true);
115 protected void configureShell(Shell newShell) {
116 super.configureShell(newShell);
117 newShell.setText(WebBrowserUIPlugin
118 .getResource("%dialogOrganizeFavoritesTitle"));
124 protected Control createDialogArea(Composite parent) {
125 Composite composite = new Composite(parent, SWT.NONE);
126 GridLayout layout = new GridLayout();
127 layout.numColumns = 2;
128 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
129 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
130 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
131 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
132 composite.setLayout(layout);
133 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
134 composite.setFont(parent.getFont());
135 // WorkbenchHelp.setHelp(composite, ContextIds.TERMINATE_SERVER_DIALOG);
137 Label label = new Label(composite, SWT.NONE);
138 label.setText(WebBrowserUIPlugin
139 .getResource("%dialogOrganizeFavoritesMessage"));
140 GridData data = new GridData();
141 data.horizontalSpan = 2;
142 label.setLayoutData(data);
144 final Table table = new Table(composite, SWT.BORDER
145 | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
146 data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
147 data.widthHint = 300;
148 data.heightHint = 150;
149 table.setLayoutData(data);
150 table.setLinesVisible(true);
152 TableLayout tableLayout = new TableLayout();
153 table.setLayout(tableLayout);
154 table.setHeaderVisible(true);
156 tableLayout.addColumnData(new ColumnWeightData(5, 50, true));
157 TableColumn col = new TableColumn(table, SWT.NONE);
158 col.setText(WebBrowserUIPlugin
159 .getResource("%dialogOrganizeFavoritesName"));
161 tableLayout.addColumnData(new ColumnWeightData(6, 60, true));
162 col = new TableColumn(table, SWT.NONE);
163 col.setText(WebBrowserUIPlugin
164 .getResource("%dialogOrganizeFavoritesURL"));
165 table.setLayout(tableLayout);
167 final TableViewer tableViewer = new TableViewer(table);
168 tableViewer.setContentProvider(new FavoriteContentProvider());
169 tableViewer.setLabelProvider(new FavoriteLabelProvider());
170 tableViewer.setInput("root");
171 tableViewer.setColumnProperties(new String[] { "name", "url" });
173 tableViewer.setCellEditors(new CellEditor[] {
174 new TextCellEditor(table), new TextCellEditor(table) });
176 ICellModifier cellModifier = new ICellModifier() {
177 public Object getValue(Object element, String property) {
178 Favorite f = (Favorite) element;
179 if ("name".equals(property))
185 public boolean canModify(Object element, String property) {
189 public void modify(Object element, String property, Object value) {
190 if (element instanceof Item)
191 element = ((Item) element).getData();
194 Favorite f = (Favorite) element;
195 String s = (String) value;
196 if ("name".equals(property))
200 tableViewer.refresh(f);
201 } catch (Exception ex) {
202 ex.printStackTrace();
206 tableViewer.setCellModifier(cellModifier);
208 final Button remove = SWTUtil.createButton(composite,
209 WebBrowserUIPlugin.getResource("%remove"));
210 remove.setEnabled(false);
213 .addSelectionChangedListener(new ISelectionChangedListener() {
214 public void selectionChanged(SelectionChangedEvent event) {
215 remove.setEnabled(!event.getSelection().isEmpty());
219 remove.addSelectionListener(new SelectionAdapter() {
220 public void widgetSelected(SelectionEvent e) {
221 int index = table.getSelectionIndex();
222 if (index < 0 || index >= favorites.size())
225 tableViewer.remove(favorites.get(index));
226 favorites.remove(index);
230 Dialog.applyDialogFont(composite);
235 protected void okPressed() {
236 WebBrowserPreference.setInternalWebBrowserFavorites(favorites);