KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > actions > LocateDnInDitAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.ui.actions;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.DN;
25 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
26 import org.apache.directory.ldapstudio.browser.core.model.IValue;
27 import org.apache.directory.ldapstudio.browser.core.model.NameException;
28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
29 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
30
31 import org.eclipse.jface.resource.ImageDescriptor;
32
33
34 /**
35  * This action is used within the entry editor and search result editor
36  * to locate and open the entry identified by the DN under the cursor.
37  *
38  * Example: Attribute "seeAlso" with value "ou=test" is selected in entry edtor.
39  * Then this action is enabled and opens entry "ou=test" in DIT.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class LocateDnInDitAction extends LocateInDitAction
45 {
46     /**
47      * Creates a new instance of LocateDnInDitAction.
48      */

49     public LocateDnInDitAction()
50     {
51     }
52
53
54     /**
55      * {@inheritDoc}
56      */

57     public String JavaDoc getText()
58     {
59         return "Locate DN in DIT";
60     }
61
62
63     /**
64      * {@inheritDoc}
65      */

66     public ImageDescriptor getImageDescriptor()
67     {
68         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_LOCATE_DN_IN_DIT );
69     }
70
71
72     /**
73      * This implementation returns a connection and DN if the selected attribute or value
74      * contains a valid DN.
75      */

76     protected ConnectionAndDn getConnectionAndDn()
77     {
78
79         if ( getSelectedAttributeHierarchies().length == 1
80             && getSelectedAttributeHierarchies()[0].getAttribute().getValueSize() == 1
81             && getSelectedSearchResults().length == 1 )
82         {
83             try
84             {
85                 IValue value = getSelectedAttributeHierarchies()[0].getAttribute().getValues()[0];
86                 if ( value.isString() && new DN( value.getStringValue() ) != null )
87                 {
88                     return new ConnectionAndDn( value.getAttribute().getEntry().getConnection(), new DN( value
89                         .getStringValue() ) );
90                 }
91             }
92             catch ( NameException e )
93             {
94                 // no valid DN
95
}
96         }
97
98         if ( getSelectedValues().length == 1 && getSelectedAttributes().length == 0 )
99         {
100             try
101             {
102                 IValue value = getSelectedValues()[0];
103                 if ( value.isString() && new DN( value.getStringValue() ) != null )
104                 {
105                     return new ConnectionAndDn( value.getAttribute().getEntry().getConnection(), new DN( value
106                         .getStringValue() ) );
107                 }
108             }
109             catch ( NameException e )
110             {
111                 // no valid DN
112
}
113         }
114
115         if ( getSelectedSearchResults().length == 1 && getSelectedAttributeHierarchies().length == 0 )
116         {
117             ISearchResult result = getSelectedSearchResults()[0];
118             return new ConnectionAndDn( result.getEntry().getConnection(), result.getEntry().getDn() );
119         }
120
121         return null;
122     }
123 }
124
Popular Tags