KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
25 import java.util.LinkedHashSet JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction;
29 import org.apache.directory.ldapstudio.browser.common.actions.CopyAction;
30 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
31 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
32 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
33 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
34
35 import org.eclipse.jface.resource.ImageDescriptor;
36 import org.eclipse.swt.dnd.TextTransfer;
37 import org.eclipse.swt.dnd.Transfer;
38
39
40 /**
41  * This class implements the Copy Attribute Description Action.
42  *
43  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
44  * @version $Rev$, $Date$
45  */

46 public class CopyAttributeDescriptionAction extends BrowserAction
47 {
48
49     /**
50      * Creates a new instance of CopyAttributeDescriptionAction.
51      */

52     public CopyAttributeDescriptionAction()
53     {
54     }
55
56
57     /**
58      * {@inheritDoc}
59      */

60     public void run()
61     {
62         StringBuffer JavaDoc text = new StringBuffer JavaDoc();
63         for ( Iterator JavaDoc iterator = getAttributeNameSet().iterator(); iterator.hasNext(); )
64         {
65             text.append( iterator.next() );
66             if ( iterator.hasNext() )
67                 text.append( BrowserCoreConstants.LINE_SEPARATOR );
68         }
69
70         if ( text.length() > 0 )
71         {
72             CopyAction.copyToClipboard( new Object JavaDoc[]
73                 { text.toString() }, new Transfer[]
74                 { TextTransfer.getInstance() } );
75         }
76     }
77
78
79     /**
80      * Gets a Set containing all the Attribute Names.
81      *
82      * @return
83      * a Set containing all the Attribute Names
84      */

85     private Set JavaDoc getAttributeNameSet()
86     {
87         Set JavaDoc<String JavaDoc> attributeNameSet = new LinkedHashSet JavaDoc<String JavaDoc>();
88         for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
89         {
90             for ( Iterator JavaDoc it = getSelectedAttributeHierarchies()[i].iterator(); it.hasNext(); )
91             {
92                 IAttribute att = ( IAttribute ) it.next();
93                 attributeNameSet.add( att.getDescription() );
94             }
95         }
96         for ( int i = 0; i < getSelectedAttributes().length; i++ )
97         {
98             attributeNameSet.add( getSelectedAttributes()[i].getDescription() );
99         }
100         for ( int i = 0; i < getSelectedValues().length; i++ )
101         {
102             attributeNameSet.add( getSelectedValues()[i].getAttribute().getDescription() );
103         }
104         return attributeNameSet;
105     }
106
107
108     /**
109      * {@inheritDoc}
110      */

111     public String JavaDoc getText()
112     {
113         if ( getAttributeNameSet().size() > 1 )
114         {
115             return "Copy Attribute Descriptions";
116         }
117         else
118         {
119             return "Copy Attribute Description";
120         }
121     }
122
123
124     /**
125      * {@inheritDoc}
126      */

127     public ImageDescriptor getImageDescriptor()
128     {
129         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_ATT );
130     }
131
132
133     /**
134      * {@inheritDoc}
135      */

136     public String JavaDoc getCommandId()
137     {
138         return null;
139     }
140
141
142     /**
143      * {@inheritDoc}
144      */

145     public boolean isEnabled()
146     {
147         return getAttributeNameSet().size() > 0;
148     }
149 }
150
Popular Tags