KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > method > MethodCustomizer


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.common.method;
21
22 import java.util.Collection JavaDoc;
23 import org.netbeans.modules.j2ee.common.method.impl.MethodCustomizerPanel;
24 import org.netbeans.modules.j2ee.common.method.impl.ValidatingPropertyChangeListener;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28
29 /**
30  *
31  * @author Martin Adamek
32  */

33 public final class MethodCustomizer {
34     
35     private final MethodCustomizerPanel panel;
36     private final String JavaDoc title;
37     private final String JavaDoc prefix;
38     private final Collection JavaDoc<MethodModel> existingMethods;
39     
40     // factory should be used to create instances
41
protected MethodCustomizer(String JavaDoc title, MethodModel methodModel, boolean hasLocal, boolean hasRemote, boolean selectLocal, boolean selectRemote,
42             boolean hasReturnType, String JavaDoc ejbql, boolean hasFinderCardinality, boolean hasExceptions, boolean hasInterfaces,
43             String JavaDoc prefix, Collection JavaDoc<MethodModel> existingMethods) {
44         this.panel = MethodCustomizerPanel.create(methodModel, hasLocal, hasRemote, selectLocal, selectRemote,
45                 hasReturnType, ejbql, hasFinderCardinality, hasExceptions, hasInterfaces);
46         this.title = title;
47         this.prefix = prefix;
48         this.existingMethods = existingMethods;
49     }
50     
51     /**
52      * Opens modal window for method customization.
53      *
54      * @return true if OK button on customizer was pressed and changes should be written to source files,
55      * false if Cancel button on customizer was pressed or if customizer was cancelled in any other way and
56      * nothing should be written to source files.
57      */

58     public boolean customizeMethod() {
59         DialogDescriptor notifyDescriptor = new DialogDescriptor(
60                 panel, title, true,
61                 DialogDescriptor.OK_CANCEL_OPTION,
62                 DialogDescriptor.PLAIN_MESSAGE,
63                 null
64                 );
65         panel.addPropertyChangeListener(new ValidatingPropertyChangeListener(panel, notifyDescriptor));
66         return DialogDisplayer.getDefault().notify(notifyDescriptor) == NotifyDescriptor.OK_OPTION;
67     }
68     
69     public MethodModel getMethodModel() {
70         return MethodModel.create(
71                 panel.getMethodName(),
72                 panel.getReturnType(),
73                 panel.getMethodBody(),
74                 panel.getParameters(),
75                 panel.getExceptions(),
76                 panel.getModifiers()
77                 );
78     }
79     
80     public boolean finderReturnIsSingle() {
81         return false;
82     }
83     
84     public boolean publishToLocal() {
85         return panel.hasLocal();
86     }
87     
88     public boolean publishToRemote() {
89         return panel.hasRemote();
90     }
91     
92     public String JavaDoc getEjbQL() {
93         return null;
94         
95     }
96     
97 }
98
Popular Tags