KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.model.URL;
27 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
28 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
29
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.swt.dnd.TextTransfer;
32 import org.eclipse.swt.dnd.Transfer;
33
34
35 /**
36  * This Action copies the URL of the selected Entry to the Clipboard.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class CopyUrlAction extends BrowserAction
42 {
43
44     /**
45      * Creates a new instance of CopyUrlAction.
46      */

47     public CopyUrlAction()
48     {
49     }
50
51
52     /**
53      * {@inheritDoc}
54      */

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

99     public String JavaDoc getText()
100     {
101         return "Copy URL";
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

108     public ImageDescriptor getImageDescriptor()
109     {
110         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_URL );
111     }
112
113
114     /**
115      * {@inheritDoc}
116      */

117     public String JavaDoc getCommandId()
118     {
119         return null;
120     }
121
122
123     /**
124      * {@inheritDoc}
125      */

126     public boolean isEnabled()
127     {
128         return getSelectedSearches().length + getSelectedEntries().length + getSelectedSearchResults().length
129             + getSelectedBookmarks().length == 1
130             || getSelectedAttributes().length + getSelectedValues().length > 0;
131     }
132 }
133
Popular Tags