KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > commit > ExcludeFromCommitAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.versioning.system.cvss.ui.actions.commit;
20
21 import org.openide.util.NbBundle;
22 import org.openide.util.actions.Presenter;
23 import org.openide.awt.Mnemonics;
24 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
25 import org.netbeans.modules.versioning.spi.VCSContext;
26
27 import javax.swing.*;
28 import java.io.File JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.util.*;
31
32 /**
33  * Excludes selected nodes from commit.
34  *
35  * @author Maros Sandor
36  */

37 public class ExcludeFromCommitAction extends AbstractAction implements Presenter.Menu {
38
39     private final VCSContext ctx;
40     private final int status;
41
42     public ExcludeFromCommitAction(VCSContext ctx) {
43         this.ctx = ctx;
44         putValue(Action.NAME, NbBundle.getBundle(ExcludeFromCommitAction.class).getString("CTL_MenuItem_ExcludeFromCommit"));
45         status = getActionStatus();
46         if (status == 1) {
47             putValue("BooleanState.Selected", Boolean.FALSE); // NOI18N
48
} else if (status == 2) {
49             putValue("BooleanState.Selected", Boolean.TRUE); // NOI18N
50
}
51         setEnabled(status != -1);
52     }
53
54     public JMenuItem getMenuPresenter() {
55         JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
56         if (status != -1) item.setSelected(status == 2);
57         Mnemonics.setLocalizedText(item, item.getText());
58         return item;
59     }
60
61     private int getActionStatus() {
62         CvsModuleConfig config = CvsModuleConfig.getDefault();
63         Set<File JavaDoc> files = ctx.getRootFiles();
64         int status = -1;
65         for (File JavaDoc file : files) {
66             if (config.isExcludedFromCommit(file)) {
67                 if (status == 1) return -1;
68                 status = 2;
69             }
70             else {
71                 if (status == 2) return -1;
72                 status = 1;
73             }
74         }
75         return status;
76     }
77
78     public void actionPerformed(ActionEvent JavaDoc e) {
79         CvsModuleConfig config = CvsModuleConfig.getDefault();
80         Set<File JavaDoc> files = ctx.getRootFiles();
81         for (File JavaDoc file : files) {
82             if (status == 1) {
83                 config.addExclusion(file);
84             } else if (status == 2) {
85                 config.removeExclusion(file);
86             }
87         }
88     }
89 }
90
Popular Tags