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 Update implements PropertyChangeListener {
057:
058: private UpdatePanel panel;
059: private JButton okButton;
060: private JButton cancelButton;
061: private File repository;
062:
063: /** Creates a new instance of Update */
064: public Update(File repository) {
065: this (repository, null);
066: }
067:
068: public Update(File repository, String defaultRevision) {
069: this .repository = repository;
070: panel = new UpdatePanel(repository);
071: okButton = new JButton();
072: org.openide.awt.Mnemonics.setLocalizedText(okButton,
073: org.openide.util.NbBundle.getMessage(
074: RevertModifications.class,
075: "CTL_UpdateForm_Action_Update")); // NOI18N
076: okButton.getAccessibleContext().setAccessibleDescription(
077: org.openide.util.NbBundle.getMessage(
078: RevertModifications.class,
079: "ACSD_UpdateForm_Action_Update")); // NOI18N
080: okButton.getAccessibleContext().setAccessibleName(
081: org.openide.util.NbBundle.getMessage(
082: RevertModifications.class,
083: "ACSN_UpdateForm_Action_Update")); // NOI18N
084: cancelButton = new JButton();
085: org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
086: org.openide.util.NbBundle.getMessage(
087: RevertModifications.class,
088: "CTL_UpdateForm_Action_Cancel")); // NOI18N
089: cancelButton.getAccessibleContext().setAccessibleDescription(
090: org.openide.util.NbBundle.getMessage(
091: RevertModifications.class,
092: "ACSD_UpdateForm_Action_Cancel")); // NOI18N
093: cancelButton.getAccessibleContext().setAccessibleName(
094: org.openide.util.NbBundle.getMessage(
095: RevertModifications.class,
096: "ACSN_UpdateForm_Action_Cancel")); // NOI18N
097: }
098:
099: public boolean showDialog() {
100: DialogDescriptor dialogDescriptor;
101: dialogDescriptor = new DialogDescriptor(panel,
102: org.openide.util.NbBundle.getMessage(
103: RevertModifications.class, "CTL_UpdateDialog",
104: repository.getName())); // NOI18N
105: dialogDescriptor.setOptions(new Object[] { okButton,
106: cancelButton });
107:
108: dialogDescriptor.setModal(true);
109: dialogDescriptor.setHelpCtx(new HelpCtx(this .getClass()));
110: dialogDescriptor.setValid(false);
111:
112: Dialog dialog = DialogDisplayer.getDefault().createDialog(
113: dialogDescriptor);
114: dialog.getAccessibleContext().setAccessibleDescription(
115: org.openide.util.NbBundle.getMessage(
116: RevertModifications.class, "ACSD_UpdateDialog",
117: repository.getName())); // NOI18N
118: dialog.setVisible(true);
119: dialog.setResizable(false);
120: boolean ret = dialogDescriptor.getValue() == okButton;
121: return ret;
122: }
123:
124: public void propertyChange(PropertyChangeEvent evt) {
125: if (okButton != null) {
126: boolean valid = ((Boolean) evt.getNewValue())
127: .booleanValue();
128: okButton.setEnabled(valid);
129: }
130: }
131:
132: public String getSelectionRevision() {
133: if (panel == null)
134: return null;
135: return panel.getSelectedRevision();
136: }
137:
138: public boolean isForcedUpdateRequested() {
139: if (panel == null)
140: return false;
141: return panel.isForcedUpdateRequested();
142: }
143: }
|