KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > actions > SelectAllAction


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.common.actions;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
30 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
31
32 import org.eclipse.jface.resource.ImageDescriptor;
33 import org.eclipse.jface.viewers.StructuredSelection;
34 import org.eclipse.jface.viewers.Viewer;
35 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
36
37
38 /**
39  * This class implements the Select All Action.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class SelectAllAction extends BrowserAction
45 {
46     private Viewer viewer;
47
48
49     /**
50      * Creates a new instance of SelectAllAction.
51      *
52      * @param viewer
53      * the attached viewer
54      */

55     public SelectAllAction( Viewer viewer )
56     {
57         this.viewer = viewer;
58     }
59
60     /**
61      * {@inheritDoc}
62      */

63     public String JavaDoc getText()
64     {
65         return "Select All";
66     }
67
68     /**
69      * {@inheritDoc}
70      */

71     public ImageDescriptor getImageDescriptor()
72     {
73         return null;
74     }
75
76     /**
77      * {@inheritDoc}
78      */

79     public String JavaDoc getCommandId()
80     {
81         return IWorkbenchActionDefinitionIds.SELECT_ALL;
82     }
83
84     /**
85      * {@inheritDoc}
86      */

87     public boolean isEnabled()
88     {
89         return true;
90     }
91
92     /**
93      * {@inheritDoc}
94      */

95     public void run()
96     {
97         if ( getInput() != null && getInput() instanceof IEntry )
98         {
99             List JavaDoc selectionList = new ArrayList JavaDoc();
100             IAttribute[] attributes = ( ( IEntry ) getInput() ).getAttributes();
101             if ( attributes != null )
102             {
103                 selectionList.addAll( Arrays.asList( attributes ) );
104                 for ( int i = 0; i < attributes.length; i++ )
105                 {
106                     selectionList.addAll( Arrays.asList( attributes[i].getValues() ) );
107                 }
108             }
109             StructuredSelection selection = new StructuredSelection( selectionList );
110             this.viewer.setSelection( selection );
111         }
112         else if ( getInput() != null && getInput() instanceof ConnectionManager )
113         {
114             StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) getInput() )
115                 .getConnections() );
116             this.viewer.setSelection( selection );
117         }
118         else if ( getSelectedConnections().length > 0 && viewer.getInput() instanceof ConnectionManager )
119         {
120             StructuredSelection selection = new StructuredSelection( ( ( ConnectionManager ) viewer.getInput() )
121                 .getConnections() );
122             this.viewer.setSelection( selection );
123         }
124     }
125 }
126
Popular Tags