Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* If you wish your version of this file to be governed by only the CDDL |
25 |
* or only the GPL Version 2, indicate your decision by adding |
26 |
* "[Contributor] elects to include this software in this distribution |
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
28 |
* single choice of license, a recipient has the option to distribute |
29 |
* your version of this file under either the CDDL, the GPL Version 2 or |
30 |
* to extend the choice of license to its licensees as provided above. |
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
32 |
* Version 2 license, then the option applies only if the new code is |
33 |
* made subject to such option by the copyright holder. |
34 |
* |
35 |
* Contributor(s): |
36 |
* |
37 |
* Portions Copyrighted 2010 Sun Microsystems, Inc. |
38 |
*/ |
39 |
|
40 |
package org.openide.windows; |
41 |
|
42 |
import java.util.EnumSet; |
43 |
import org.openide.util.Lookup; |
44 |
|
45 |
/** |
46 |
* Capability of an InputOutput of finer grained selection of a component. |
47 |
* <p> |
48 |
* InputOutput.select() does too much. |
49 |
* @author ivan |
50 |
*/ |
51 |
public abstract class IOSelect { |
52 |
|
53 |
/** |
54 |
* Additional operations to perform when issuing {@link IOSelect#select}. |
55 |
* @author ivan |
56 |
*/ |
57 |
public static enum AdditionalOperation { |
58 |
/** |
59 |
* Additionally issue open() on the TopComponent containing the InputOutput. |
60 |
*/ |
61 |
OPEN, |
62 |
|
63 |
/** |
64 |
* Additionally issue requestVisible() on the TopComponent containing the InputOutput. |
65 |
*/ |
66 |
REQUEST_VISIBLE, |
67 |
|
68 |
/** |
69 |
* Additionally issue requestActive() on the TopComponent containing the InputOutput. |
70 |
*/ |
71 |
REQUEST_ACTIVE |
72 |
} |
73 |
|
74 |
private static IOSelect find(InputOutput io) { |
75 |
if (io instanceof Lookup.Provider) { |
76 |
Lookup.Provider p = (Lookup.Provider) io; |
77 |
return p.getLookup().lookup(IOSelect.class); |
78 |
} |
79 |
return null; |
80 |
} |
81 |
|
82 |
/** |
83 |
* With a null or empty 'extraOps' simply selects this io |
84 |
* without involving it's containing TopComponent. |
85 |
* <p> |
86 |
* If this capability is not supported then regular InputOutput.select() |
87 |
* will be called. |
88 |
* @param io InputOutput to operate on. |
89 |
* @param extraOps Additional operations to apply to the containing |
90 |
* TopComponent. |
91 |
*/ |
92 |
public static void select(InputOutput io, EnumSet<AdditionalOperation> extraOps) { |
93 |
IOSelect ios = find(io); |
94 |
if (ios != null) |
95 |
ios.select(extraOps); |
96 |
else |
97 |
io.select(); // fallback |
98 |
} |
99 |
|
100 |
/** |
101 |
* Checks whether this feature is supported for provided IO |
102 |
* @param io IO to check on |
103 |
* @return true if supported |
104 |
*/ |
105 |
public static boolean isSupported(InputOutput io) { |
106 |
return find(io) != null; |
107 |
} |
108 |
|
109 |
/** |
110 |
* With a null or empty 'extraOps' simply selects this io |
111 |
* without involving it's containing TopComponent. |
112 |
* @param extraOps Additional operations to apply to the containing |
113 |
* TopComponent. |
114 |
*/ |
115 |
abstract protected void select(EnumSet<AdditionalOperation> extraOps); |
116 |
} |