KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > searchresult > SearchResultEditorPasteAction


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.editors.searchresult;
22
23
24 import org.apache.directory.ldapstudio.browser.common.actions.PasteAction;
25 import org.apache.directory.ldapstudio.browser.common.dnd.ValuesTransfer;
26 import org.apache.directory.ldapstudio.browser.core.jobs.CreateValuesJob;
27 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
28 import org.apache.directory.ldapstudio.browser.core.model.IValue;
29
30
31 /**
32  * Special paste action to copy the values of a copied attr-val to another
33  * attribute.
34  */

35 public class SearchResultEditorPasteAction extends PasteAction
36 {
37
38     public SearchResultEditorPasteAction()
39     {
40         super();
41     }
42
43
44     public String JavaDoc getText()
45     {
46         IValue[] values = getValuesToPaste();
47         if ( values != null )
48         {
49             return values.length > 1 ? "Paste Values" : "Paste Value";
50         }
51
52         return "Paste";
53     }
54
55
56     public boolean isEnabled()
57     {
58         if ( this.getValuesToPaste() != null )
59         {
60             return true;
61         }
62
63         return false;
64     }
65
66
67     public void run()
68     {
69         IValue[] values = getValuesToPaste();
70         if ( values != null )
71         {
72
73             String JavaDoc attributeDescription = getSelectedAttributeHierarchies()[0].getAttribute().getDescription();
74
75             String JavaDoc[] attributeDescriptions = new String JavaDoc[values.length];
76             Object JavaDoc[] rawValues = new Object JavaDoc[values.length];
77             for ( int v = 0; v < values.length; v++ )
78             {
79                 attributeDescriptions[v] = attributeDescription;
80                 rawValues[v] = values[v].getRawValue();
81             }
82             IEntry entry = getSelectedAttributeHierarchies()[0].getAttribute().getEntry();
83
84             new CreateValuesJob( entry, attributeDescriptions, rawValues ).execute();
85         }
86     }
87
88
89     /**
90      * Conditions: - an search result and a multiattribute are selected -
91      * there are IValues in clipboard
92      *
93      * @return
94      */

95     private IValue[] getValuesToPaste()
96     {
97         if ( getSelectedEntries().length + getSelectedBookmarks().length + getSelectedValues().length
98             + getSelectedAttributes().length + getSelectedSearches().length + getSelectedConnections().length == 0
99             && getSelectedSearchResults().length == 1
100             && getSelectedAttributeHierarchies().length == 1
101             && getSelectedAttributeHierarchies()[0].size() == 1 )
102         {
103
104             Object JavaDoc content = this.getFromClipboard( ValuesTransfer.getInstance() );
105             if ( content != null && content instanceof IValue[] )
106             {
107                 IValue[] values = ( IValue[] ) content;
108                 return values;
109             }
110
111             // Object content =
112
// this.getFromClipboard(LdifAttrValLinesTransfer.getInstance());
113
// if (content != null && content instanceof LdifAttrValLine[])
114
// {
115
// LdifAttrValLine[] lines = (LdifAttrValLine[]) content;
116
// return lines;
117
// }
118
}
119
120         return null;
121     }
122
123 }
124
Popular Tags