KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > cleanup > CleanUpModifyDialog


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.preferences.cleanup;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Shell;
24
25 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
26 import org.eclipse.jdt.internal.corext.util.Messages;
27
28 import org.eclipse.jdt.ui.JavaUI;
29
30 import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog;
31 import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager;
32 import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore;
33 import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile;
34
35 public class CleanUpModifyDialog extends ModifyDialog {
36     
37     /**
38      * Constant array for boolean selection
39      */

40     static String JavaDoc[] FALSE_TRUE = {
41         CleanUpConstants.FALSE,
42         CleanUpConstants.TRUE
43     };
44     
45     private Label fCountLabel;
46     private CleanUpTabPage[] fPages;
47
48     public CleanUpModifyDialog(Shell parentShell, Profile profile, ProfileManager profileManager, ProfileStore profileStore, boolean newProfile, String JavaDoc dialogPreferencesKey, String JavaDoc lastSavePathKey) {
49         super(parentShell, profile, profileManager, profileStore, newProfile, dialogPreferencesKey, lastSavePathKey);
50     }
51
52     /**
53      * {@inheritDoc}
54      */

55     protected void addPages(final Map JavaDoc values) {
56         fPages= new CleanUpTabPage[5];
57         fPages[0]= new CodeStyleTabPage(this, values);
58         fPages[1]= new MemberAccessesTabPage(this, values);
59         fPages[2]= new UnnecessaryCodeTabPage(this, values);
60         fPages[3]= new MissingCodeTabPage(this, values);
61         fPages[4]= new CodeFormatingTabPage(this, values);
62         
63         addTabPage(CleanUpMessages.CleanUpModifyDialog_TabPageName_CodeStyle, fPages[0]);
64         addTabPage(CleanUpMessages.CleanUpModifyDialog_TabPageName_MemberAccesses, fPages[1]);
65         addTabPage(CleanUpMessages.CleanUpModifyDialog_TabPageName_UnnecessaryCode, fPages[2]);
66         addTabPage(CleanUpMessages.CleanUpModifyDialog_TabPageName_MissingCode, fPages[3]);
67         addTabPage(CleanUpMessages.CleanUpModifyDialog_TabPageName_CodeFormating, fPages[4]);
68     }
69     
70     protected Control createDialogArea(Composite parent) {
71         Composite control= (Composite)super.createDialogArea(parent);
72         
73         fCountLabel= new Label(control, SWT.NONE);
74         fCountLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
75         fCountLabel.setFont(parent.getFont());
76         updateCountLabel();
77         
78         return control;
79     }
80     
81     public void updateStatus(IStatus status) {
82         int count= 0;
83         for (int i= 0; i < fPages.length; i++) {
84             count+= fPages[i].getSelectedCleanUpCount();
85         }
86         if (count == 0) {
87             super.updateStatus(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, CleanUpMessages.CleanUpModifyDialog_SelectOne_Error));
88         } else {
89             super.updateStatus(status);
90         }
91     }
92     
93     public void valuesModified() {
94         super.valuesModified();
95         updateCountLabel();
96     }
97     
98     private void updateCountLabel() {
99         int size= 0, count= 0;
100         for (int i= 0; i < fPages.length; i++) {
101             size+= fPages[i].getCleanUpCount();
102             count+= fPages[i].getSelectedCleanUpCount();
103         }
104         
105         fCountLabel.setText(Messages.format(CleanUpMessages.CleanUpModifyDialog_XofYSelected_Label, new Object JavaDoc[] {new Integer JavaDoc(count), new Integer JavaDoc(size)}));
106     }
107 }
108
Popular Tags