KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.common.dialogs.FilterWidgetDialog;
27 import org.apache.directory.ldapstudio.browser.core.jobs.InitializeChildrenJob;
28 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
29
30 import org.eclipse.jface.dialogs.Dialog;
31 import org.eclipse.jface.resource.ImageDescriptor;
32
33
34 /**
35  * This action opens the Filter Children Dialog and sets the children filter to the
36  * currently selected entry. It is useful when browsing the DIT and entries with
37  * many child nodes.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

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

48     public FilterChildrenAction()
49     {
50         super();
51     }
52
53
54     /**
55      * {@inheritDoc}
56      */

57     public void run()
58     {
59         if ( getSelectedEntries().length == 1 )
60         {
61             FilterWidgetDialog dialog = new FilterWidgetDialog( getShell(), "Filter Children", getSelectedEntries()[0]
62                 .getChildrenFilter(), getSelectedEntries()[0].getConnection() );
63             if ( dialog.open() == Dialog.OK )
64             {
65                 String JavaDoc newFilter = dialog.getFilter();
66
67                 if ( newFilter == null || "".equals( newFilter.trim() ) )
68                 {
69                     getSelectedEntries()[0].setChildrenFilter( null );
70                 }
71                 else
72                 {
73                     getSelectedEntries()[0].setChildrenFilter( newFilter.trim() );
74                 }
75                 new InitializeChildrenJob( new IEntry[]
76                     { getSelectedEntries()[0] } ).execute();
77
78             }
79         }
80     }
81
82
83     /**
84      * {@inheritDoc}
85      */

86     public String JavaDoc getText()
87     {
88         return "Filter Children...";
89     }
90
91
92     /**
93      * {@inheritDoc}
94      */

95     public ImageDescriptor getImageDescriptor()
96     {
97         return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_FILTER_DIT );
98     }
99
100
101     /**
102      * {@inheritDoc}
103      */

104     public String JavaDoc getCommandId()
105     {
106         return null;
107     }
108
109
110     /**
111      * {@inheritDoc}
112      */

113     public boolean isEnabled()
114     {
115         return getSelectedSearches().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0
116             && getSelectedEntries().length == 1
117             && ( getSelectedEntries()[0].hasChildren() || getSelectedEntries()[0].getChildrenFilter() != null );
118     }
119 }
120
Popular Tags