001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences.cleanup;
011:
012: import java.util.Map;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Status;
016:
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.layout.GridData;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Control;
021: import org.eclipse.swt.widgets.Label;
022: import org.eclipse.swt.widgets.Shell;
023:
024: import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
025: import org.eclipse.jdt.internal.corext.util.Messages;
026:
027: import org.eclipse.jdt.ui.JavaUI;
028:
029: import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialog;
030: import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager;
031: import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore;
032: import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile;
033:
034: public class CleanUpModifyDialog extends ModifyDialog {
035:
036: /**
037: * Constant array for boolean selection
038: */
039: static String[] FALSE_TRUE = { CleanUpConstants.FALSE,
040: CleanUpConstants.TRUE };
041:
042: private Label fCountLabel;
043: private CleanUpTabPage[] fPages;
044:
045: public CleanUpModifyDialog(Shell parentShell, Profile profile,
046: ProfileManager profileManager, ProfileStore profileStore,
047: boolean newProfile, String dialogPreferencesKey,
048: String lastSavePathKey) {
049: super (parentShell, profile, profileManager, profileStore,
050: newProfile, dialogPreferencesKey, lastSavePathKey);
051: }
052:
053: /**
054: * {@inheritDoc}
055: */
056: protected void addPages(final Map values) {
057: fPages = new CleanUpTabPage[5];
058: fPages[0] = new CodeStyleTabPage(
059: this ,
060: values,
061: false,
062: CleanUpMessages.CleanUpModifyDialog_TabPageName_CodeStyle);
063: fPages[1] = new MemberAccessesTabPage(
064: this ,
065: values,
066: false,
067: CleanUpMessages.CleanUpModifyDialog_TabPageName_MemberAccesses);
068: fPages[2] = new UnnecessaryCodeTabPage(
069: this ,
070: values,
071: false,
072: CleanUpMessages.CleanUpModifyDialog_TabPageName_UnnecessaryCode);
073: fPages[3] = new MissingCodeTabPage(
074: this ,
075: values,
076: false,
077: CleanUpMessages.CleanUpModifyDialog_TabPageName_MissingCode);
078: fPages[4] = new CodeFormatingTabPage(
079: this ,
080: values,
081: false,
082: CleanUpMessages.CleanUpModifyDialog_TabPageName_CodeFormating);
083:
084: for (int i = 0; i < fPages.length; i++) {
085: addTabPage(fPages[i].getTitle(), fPages[i]);
086: }
087: }
088:
089: protected Control createDialogArea(Composite parent) {
090: Composite control = (Composite) super .createDialogArea(parent);
091:
092: fCountLabel = new Label(control, SWT.NONE);
093: fCountLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
094: false));
095: fCountLabel.setFont(parent.getFont());
096: updateCountLabel();
097:
098: return control;
099: }
100:
101: public void updateStatus(IStatus status) {
102: int count = 0;
103: for (int i = 0; i < fPages.length; i++) {
104: count += fPages[i].getSelectedCleanUpCount();
105: }
106: if (count == 0) {
107: super
108: .updateStatus(new Status(
109: IStatus.ERROR,
110: JavaUI.ID_PLUGIN,
111: CleanUpMessages.CleanUpModifyDialog_SelectOne_Error));
112: } else {
113: super .updateStatus(status);
114: }
115: }
116:
117: public void valuesModified() {
118: super .valuesModified();
119: updateCountLabel();
120: }
121:
122: private void updateCountLabel() {
123: int size = 0, count = 0;
124: for (int i = 0; i < fPages.length; i++) {
125: size += fPages[i].getCleanUpCount();
126: count += fPages[i].getSelectedCleanUpCount();
127: }
128:
129: fCountLabel
130: .setText(Messages
131: .format(
132: CleanUpMessages.CleanUpModifyDialog_XofYSelected_Label,
133: new Object[] { new Integer(count),
134: new Integer(size) }));
135: }
136: }
|