KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > ShowActivitiesDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.wizards;
12
13 import java.text.DateFormat JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.dialogs.IDialogSettings;
19 import org.eclipse.jface.viewers.ColumnWeightData;
20 import org.eclipse.jface.viewers.TableLayout;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.graphics.Point;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.update.core.SiteManager;
31 import org.eclipse.update.internal.core.InstallConfiguration;
32 import org.eclipse.update.internal.ui.UpdateUI;
33 import org.eclipse.update.internal.ui.UpdateUIMessages;
34
35
36
37 public class ShowActivitiesDialog extends Dialog {
38     private TableViewer activitiesViewer;
39
40     // location configuration
41
private IDialogSettings dialogSettings;
42     private Point dialogLocation;
43     private Point dialogSize;
44
45     /**
46      * @param parentShell
47      */

48     public ShowActivitiesDialog(Shell parentShell) {
49         super(parentShell);
50         setShellStyle(SWT.RESIZE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
51         readConfiguration();
52     }
53     
54     public void create() {
55         super.create();
56         // dialog location
57
if (dialogLocation != null)
58             getShell().setLocation(dialogLocation);
59         
60         // dialog size
61
if (dialogSize != null)
62             getShell().setSize(dialogSize);
63         else
64             getShell().setSize(500,500);
65         
66         
67         applyDialogFont(buttonBar);
68         getButton(IDialogConstants.OK_ID).setFocus();
69     }
70
71     protected Control createDialogArea(Composite parent) {
72         Composite container = new Composite(parent, SWT.NONE);
73         GridLayout layout = new GridLayout();
74         layout.numColumns = 1;
75         layout.makeColumnsEqualWidth = false;
76         container.setLayout(layout);
77         GridData gd = new GridData(GridData.FILL_BOTH);
78         gd.grabExcessHorizontalSpace = true;
79         gd.grabExcessVerticalSpace = true;
80         container.setLayoutData(gd);
81         createDescriptionSection(container);
82         createActivitiesViewer(container);
83         Dialog.applyDialogFont(container);
84         return container;
85     }
86
87     protected Control createDescriptionSection(Composite parent){
88         Composite container = new Composite(parent, SWT.NONE);
89         GridLayout layout = new GridLayout();
90         layout.numColumns = 2;
91         layout.makeColumnsEqualWidth = false;
92         container.setLayout(layout);
93         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
94         container.setLayoutData(gd);
95         try {
96             Label targetLabel = new Label(container, SWT.NONE);
97             targetLabel.setText(UpdateUIMessages.ShowActivitiesDialog_date);
98             Label target = new Label(container, SWT.NONE);
99             DateFormat JavaDoc df = DateFormat.getDateTimeInstance();
100             String JavaDoc localizedDate = df.format(SiteManager.getLocalSite().getCurrentConfiguration().getCreationDate());
101             target.setText(localizedDate);
102             
103             Label urlLabel = new Label(container, SWT.NONE);
104             urlLabel.setText(UpdateUIMessages.ShowActivitiesDialog_loc);
105             Label url = new Label(container, SWT.NONE);
106             url.setText(((InstallConfiguration)SiteManager.getLocalSite().getCurrentConfiguration()).getURL().getFile());
107             
108             
109         } catch (CoreException e) {
110             UpdateUI.logException(e);
111         }
112         return container;
113     }
114     protected Control createActivitiesViewer(Composite parent) {
115         Composite composite = new Composite(parent, SWT.NONE);
116         GridLayout gridLayout = new GridLayout();
117         gridLayout.marginHeight = gridLayout.marginWidth = 4;
118         composite.setLayout(gridLayout);
119
120         GridData gd = new GridData(GridData.FILL_BOTH);
121 // gd.grabExcessHorizontalSpace = true;
122
// gd.grabExcessVerticalSpace = true;
123

124         composite.setLayoutData(gd);
125
126         
127         Label label = new Label(composite, SWT.NONE);
128         label.setText(UpdateUIMessages.ShowActivitiesDialog_label);
129         activitiesViewer = ActivitiesTableViewer.createViewer(composite, true);
130
131         TableLayout layout = new TableLayout();
132         layout.addColumnData(new ColumnWeightData(8, 20, false));
133         layout.addColumnData(new ColumnWeightData(50, 160, true));
134         layout.addColumnData(new ColumnWeightData(50, 183, true));
135         layout.addColumnData(new ColumnWeightData(50, 100, true));
136
137         activitiesViewer.getTable().setLayout(layout);
138         try {
139             activitiesViewer.setInput(SiteManager.getLocalSite().getCurrentConfiguration());
140         } catch (CoreException e) {
141         }
142         Dialog.applyDialogFont(composite);
143         return composite;
144     }
145
146     protected void createButtonsForButtonBar(Composite parent) {
147         // create OK button only by default
148
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
149     }
150
151     public boolean close() {
152         storeSettings();
153         return super.close();
154     }
155     
156     /**
157      * Stores the current state in the dialog settings.
158      * @since 2.0
159      */

160     private void storeSettings() {
161         writeConfiguration();
162     }
163     /**
164      * Returns the dialog settings object used to share state
165      * between several event detail dialogs.
166      *
167      * @return the dialog settings to be used
168      */

169     private IDialogSettings getDialogSettings() {
170         IDialogSettings settings = UpdateUI.getDefault().getDialogSettings();
171         dialogSettings = settings.getSection(getClass().getName());
172         if (dialogSettings == null)
173             dialogSettings= settings.addNewSection(getClass().getName());
174         return dialogSettings;
175     }
176
177     /**
178      * Initializes itself from the dialog settings with the same state
179      * as at the previous invocation.
180      */

181     private void readConfiguration() {
182         IDialogSettings s= getDialogSettings();
183         try {
184             int x= s.getInt("x"); //$NON-NLS-1$
185
int y= s.getInt("y"); //$NON-NLS-1$
186
dialogLocation= new Point(x, y);
187             
188             x = s.getInt("width"); //$NON-NLS-1$
189
y = s.getInt("height"); //$NON-NLS-1$
190
dialogSize = new Point(x,y);
191         } catch (NumberFormatException JavaDoc e) {
192             dialogLocation= null;
193             dialogSize = null;
194         }
195     }
196     
197     private void writeConfiguration(){
198         IDialogSettings s = getDialogSettings();
199         Point location = getShell().getLocation();
200         s.put("x", location.x); //$NON-NLS-1$
201
s.put("y", location.y); //$NON-NLS-1$
202

203         Point size = getShell().getSize();
204         s.put("width", size.x); //$NON-NLS-1$
205
s.put("height", size.y); //$NON-NLS-1$
206
}
207 }
208
Popular Tags