001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.mercurial.ui.update;
042:
043: import java.awt.Dialog;
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046: import javax.swing.JButton;
047: import org.openide.DialogDescriptor;
048: import org.openide.DialogDisplayer;
049: import org.openide.util.HelpCtx;
050: import java.io.File;
051:
052: /**
053: *
054: * @author Padraig O'Briain
055: */
056: public class RevertModifications implements PropertyChangeListener {
057:
058: private RevertModificationsPanel panel;
059: private JButton okButton;
060: private JButton cancelButton;
061:
062: /** Creates a new instance of RevertModifications */
063: public RevertModifications(File repository, File[] files) {
064: this (repository, files, null);
065: }
066:
067: public RevertModifications(File repository, File[] files,
068: String defaultRevision) {
069: panel = new RevertModificationsPanel(repository, files);
070: okButton = new JButton();
071: org.openide.awt.Mnemonics.setLocalizedText(okButton,
072: org.openide.util.NbBundle.getMessage(
073: RevertModifications.class,
074: "CTL_RevertForm_Action_Revert")); // NOI18N
075: okButton.getAccessibleContext().setAccessibleDescription(
076: org.openide.util.NbBundle.getMessage(
077: RevertModifications.class,
078: "ACSD_RevertForm_Action_Revert")); // NOI18N
079: okButton.getAccessibleContext().setAccessibleName(
080: org.openide.util.NbBundle.getMessage(
081: RevertModifications.class,
082: "ACSN_RevertForm_Action_Revert")); // NOI18N
083: cancelButton = new JButton();
084: org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
085: org.openide.util.NbBundle.getMessage(
086: RevertModifications.class,
087: "CTL_RevertForm_Action_Cancel")); // NOI18N
088: cancelButton.getAccessibleContext().setAccessibleDescription(
089: org.openide.util.NbBundle.getMessage(
090: RevertModifications.class,
091: "ACSD_RevertForm_Action_Cancel")); // NOI18N
092: cancelButton.getAccessibleContext().setAccessibleName(
093: org.openide.util.NbBundle.getMessage(
094: RevertModifications.class,
095: "ACSN_RevertForm_Action_Cancel")); // NOI18N
096: }
097:
098: public boolean showDialog() {
099: File[] revertFiles = panel.getRevertFiles();
100: DialogDescriptor dialogDescriptor;
101: if (revertFiles.length == 1) {
102: dialogDescriptor = new DialogDescriptor(panel,
103: org.openide.util.NbBundle.getMessage(
104: RevertModifications.class,
105: "CTL_RevertDialog", revertFiles[0]
106: .getName())); // NOI18N
107: } else {
108: dialogDescriptor = new DialogDescriptor(panel,
109: org.openide.util.NbBundle.getMessage(
110: RevertModifications.class,
111: "CTL_MultiRevertDialog")); // NOI18N
112: }
113: dialogDescriptor.setOptions(new Object[] { okButton,
114: cancelButton });
115:
116: dialogDescriptor.setModal(true);
117: dialogDescriptor.setHelpCtx(new HelpCtx(this .getClass()));
118: dialogDescriptor.setValid(false);
119:
120: Dialog dialog = DialogDisplayer.getDefault().createDialog(
121: dialogDescriptor);
122: if (revertFiles.length == 1) {
123: dialog.getAccessibleContext().setAccessibleDescription(
124: org.openide.util.NbBundle.getMessage(
125: RevertModifications.class,
126: "ACSD_RevertDialog", revertFiles[0]
127: .getName())); // NOI18N
128: } else {
129: dialog.getAccessibleContext().setAccessibleDescription(
130: org.openide.util.NbBundle.getMessage(
131: RevertModifications.class,
132: "ACSD_MultiRevertDialog")); // NOI18N
133: }
134: dialog.setVisible(true);
135: dialog.setResizable(false);
136: boolean ret = dialogDescriptor.getValue() == okButton;
137: return ret;
138: }
139:
140: public void propertyChange(PropertyChangeEvent evt) {
141: if (okButton != null) {
142: boolean valid = ((Boolean) evt.getNewValue())
143: .booleanValue();
144: okButton.setEnabled(valid);
145: }
146: }
147:
148: public String getSelectionRevision() {
149: if (panel == null)
150: return null;
151: return panel.getSelectedRevision();
152: }
153:
154: public boolean isBackupRequested() {
155: if (panel == null)
156: return false;
157: return panel.isBackupRequested();
158: }
159:
160: }
|