KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > OpenTypeSelectionDialog2


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.ui.dialogs;
12
13 import org.eclipse.swt.graphics.Point;
14 import org.eclipse.swt.graphics.Rectangle;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Shell;
18
19 import org.eclipse.jface.dialogs.DialogSettings;
20 import org.eclipse.jface.dialogs.IDialogSettings;
21 import org.eclipse.jface.operation.IRunnableContext;
22
23 import org.eclipse.ui.PlatformUI;
24
25 import org.eclipse.jdt.core.search.IJavaSearchScope;
26
27 import org.eclipse.jdt.ui.dialogs.TypeSelectionExtension;
28
29 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32 /**
33  * @deprecated use {@link OpenTypeSelectionDialog}
34  */

35 public class OpenTypeSelectionDialog2 extends TypeSelectionDialog2 {
36
37     private IDialogSettings fSettings;
38     private Point fLocation;
39     private Point fSize;
40
41     private static final String JavaDoc DIALOG_SETTINGS= "org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2"; //$NON-NLS-1$
42
private static final String JavaDoc WIDTH= "width"; //$NON-NLS-1$
43
private static final String JavaDoc HEIGHT= "height"; //$NON-NLS-1$
44

45     public OpenTypeSelectionDialog2(Shell parent, boolean multi, IRunnableContext context, IJavaSearchScope scope, int elementKinds) {
46         this(parent, multi, context, scope, elementKinds, null);
47     }
48     
49     public OpenTypeSelectionDialog2(Shell parent, boolean multi, IRunnableContext context,
50             IJavaSearchScope scope, int elementKinds, TypeSelectionExtension extension) {
51         super(parent, multi, context, scope, elementKinds, extension);
52         IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings();
53         fSettings= settings.getSection(DIALOG_SETTINGS);
54         if (fSettings == null) {
55             fSettings= new DialogSettings(DIALOG_SETTINGS);
56             settings.addSection(fSettings);
57             fSettings.put(WIDTH, 480);
58             fSettings.put(HEIGHT, 320);
59         }
60     }
61     
62     protected void configureShell(Shell newShell) {
63         super.configureShell(newShell);
64         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.OPEN_TYPE_DIALOG);
65     }
66
67     protected Point getInitialSize() {
68         Point result= super.getInitialSize();
69         if (fSize != null) {
70             result.x= Math.max(result.x, fSize.x);
71             result.y= Math.max(result.y, fSize.y);
72             Rectangle display= getShell().getDisplay().getClientArea();
73             result.x= Math.min(result.x, display.width);
74             result.y= Math.min(result.y, display.height);
75         }
76         return result;
77     }
78     
79     protected Point getInitialLocation(Point initialSize) {
80         Point result= super.getInitialLocation(initialSize);
81         if (fLocation != null) {
82             result.x= fLocation.x;
83             result.y= fLocation.y;
84             Rectangle display= getShell().getDisplay().getClientArea();
85             int xe= result.x + initialSize.x;
86             if (xe > display.width) {
87                 result.x-= xe - display.width;
88             }
89             int ye= result.y + initialSize.y;
90             if (ye > display.height) {
91                 result.y-= ye - display.height;
92             }
93         }
94         return result;
95     }
96     
97     protected Control createDialogArea(Composite parent) {
98         readSettings();
99         return super.createDialogArea(parent);
100     }
101     
102     public boolean close() {
103         writeSettings();
104         return super.close();
105     }
106     
107     /**
108      * Initializes itself from the dialog settings with the same state
109      * as at the previous invocation.
110      */

111     private void readSettings() {
112         try {
113             int x= fSettings.getInt("x"); //$NON-NLS-1$
114
int y= fSettings.getInt("y"); //$NON-NLS-1$
115
fLocation= new Point(x, y);
116         } catch (NumberFormatException JavaDoc e) {
117             fLocation= null;
118         }
119         try {
120             int width= fSettings.getInt("width"); //$NON-NLS-1$
121
int height= fSettings.getInt("height"); //$NON-NLS-1$
122
fSize= new Point(width, height);
123
124         } catch (NumberFormatException JavaDoc e) {
125             fSize= null;
126         }
127     }
128
129     /**
130      * Stores it current configuration in the dialog store.
131      */

132     private void writeSettings() {
133         Point location= getShell().getLocation();
134         fSettings.put("x", location.x); //$NON-NLS-1$
135
fSettings.put("y", location.y); //$NON-NLS-1$
136

137         Point size= getShell().getSize();
138         fSettings.put("width", size.x); //$NON-NLS-1$
139
fSettings.put("height", size.y); //$NON-NLS-1$
140
}
141 }
142
Popular Tags