KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.actions.BrowserAction;
25 import org.apache.directory.ldapstudio.browser.common.actions.CopyAction;
26 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
28 import org.eclipse.jface.resource.ImageDescriptor;
29 import org.eclipse.swt.dnd.TextTransfer;
30 import org.eclipse.swt.dnd.Transfer;
31
32
33 /**
34  * This class implements the Copy Drag'n'Drop Action.
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class CopyDnAction extends BrowserAction
40 {
41
42     /**
43      * Creates a new instance of CopyDnAction.
44      */

45     public CopyDnAction()
46     {
47     }
48
49
50     /**
51      * {@inheritDoc}
52      */

53     public void run()
54     {
55         String JavaDoc dn = null;
56         if ( getSelectedEntries().length > 0 )
57         {
58             dn = getSelectedEntries()[0].getDn().toString();
59         }
60         else if ( getSelectedAttributes().length > 0 )
61         {
62             dn = getSelectedAttributes()[0].getEntry().getDn().toString();
63         }
64         else if ( getSelectedAttributeHierarchies().length > 0 )
65         {
66             dn = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getDn().toString();
67         }
68         else if ( getSelectedValues().length > 0 )
69         {
70             dn = getSelectedValues()[0].getAttribute().getEntry().getDn().toString();
71         }
72         else if ( getSelectedSearchResults().length > 0 )
73         {
74             dn = getSelectedSearchResults()[0].getDn().toString();
75         }
76         else if ( getSelectedBookmarks().length > 0 )
77         {
78             dn = getSelectedBookmarks()[0].getDn().toString();
79         }
80
81         if ( dn != null )
82         {
83             CopyAction.copyToClipboard( new Object JavaDoc[]
84                 { dn }, new Transfer[]
85                 { TextTransfer.getInstance() } );
86         }
87     }
88
89
90     /**
91      * {@inheritDoc}
92      */

93     public String JavaDoc getText()
94     {
95         return "Copy DN";
96     }
97
98
99     /**
100      * {@inheritDoc}
101      */

102     public ImageDescriptor getImageDescriptor()
103     {
104         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_DN );
105     }
106
107
108     /**
109      * {@inheritDoc}
110      */

111     public String JavaDoc getCommandId()
112     {
113         return null;
114     }
115
116
117     /**
118      * {@inheritDoc}
119      */

120     public boolean isEnabled()
121     {
122         return getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 1
123             || getSelectedAttributes().length + getSelectedValues().length > 0;
124     }
125 }
126
Popular Tags