KickJava   Java API By Example, From Geeks To Geeks.

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


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.widgets.browser.BrowserCategory;
25 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserEntryPage;
26 import org.apache.directory.ldapstudio.browser.common.widgets.browser.BrowserSearchResultPage;
27 import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
28 import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
29 import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
30 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
31 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
32 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
33 import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
34 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
35 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
36 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
37 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
38 import org.apache.directory.ldapstudio.browser.core.model.IValue;
39 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
40 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
41 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
42
43 import org.eclipse.jface.action.IAction;
44 import org.eclipse.jface.resource.ImageDescriptor;
45 import org.eclipse.jface.viewers.ISelection;
46 import org.eclipse.swt.widgets.Shell;
47 import org.eclipse.ui.IWorkbenchWindow;
48 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
49 import org.eclipse.ui.PlatformUI;
50
51
52 /**
53  * This abstract class must be extended by each Action related to the Browser.
54  *
55  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
56  * @version $Rev$, $Date$
57  */

58 public abstract class BrowserAction implements IWorkbenchWindowActionDelegate
59 {
60     /** The selected Connections */
61     private IConnection[] selectedConnections;
62
63     /** The selected Browser View Categories */
64     private BrowserCategory[] selectedBrowserViewCategories;
65
66     /** The selected Entries */
67     private IEntry[] selectedEntries;
68
69     /** The selected Browser Entry Pages */
70     private BrowserEntryPage[] selectedBrowserEntryPages;
71
72     /** The selected Searches */
73     private ISearch[] selectedSearches;
74
75     /** The selected Search Results */
76     private ISearchResult[] selectedSearchResults;
77
78     /** The selected Browser Search Result Pages */
79     private BrowserSearchResultPage[] selectedBrowserSearchResultPages;
80
81     /** The selected Bookmarks */
82     private IBookmark[] selectedBookmarks;
83
84     /** The selected Attributes */
85     private IAttribute[] selectedAttributes;
86
87     /** The selected Attribute Hierarchies */
88     private AttributeHierarchy[] selectedAttributeHierarchies;
89
90     /** The selected Values */
91     private IValue[] selectedValues;
92
93     /** The selectec LDIF Model */
94     private LdifFile selectedLdifModel;
95
96     /** The selected LDIF Containers */
97     private LdifContainer[] selectedLdifContainers;
98
99     /** The selected LDIF Parts */
100     private LdifPart[] selectedLdifParts;
101
102     /** The input */
103     private Object JavaDoc input;
104
105
106     /**
107      * Creates a new instance of BrowserAction.
108      */

109     protected BrowserAction()
110     {
111         this.init();
112     }
113
114
115     /**
116      * {@inheritDoc}
117      */

118     public void init( IWorkbenchWindow window )
119     {
120         this.init();
121     }
122
123
124     /**
125      * {@inheritDoc}
126      */

127     public void run( IAction action )
128     {
129         this.run();
130     }
131
132
133     /**
134      * {@inheritDoc}
135      */

136     public void selectionChanged( IAction action, ISelection selection )
137     {
138         setSelectedConnections( SelectionUtils.getConnections( selection ) );
139
140         setSelectedBrowserViewCategories( SelectionUtils.getBrowserViewCategories( selection ) );
141         setSelectedEntries( SelectionUtils.getEntries( selection ) );
142         setSelectedBrowserEntryPages( SelectionUtils.getBrowserEntryPages( selection ) );
143         setSelectedSearchResults( SelectionUtils.getSearchResults( selection ) );
144         setSelectedBrowserSearchResultPages( SelectionUtils.getBrowserSearchResultPages( selection ) );
145         setSelectedBookmarks( SelectionUtils.getBookmarks( selection ) );
146
147         setSelectedSearches( SelectionUtils.getSearches( selection ) );
148
149         setSelectedAttributes( SelectionUtils.getAttributes( selection ) );
150         setSelectedAttributeHierarchies( SelectionUtils.getAttributeHierarchie( selection ) );
151         setSelectedValues( SelectionUtils.getValues( selection ) );
152
153         action.setEnabled( this.isEnabled() );
154         action.setText( this.getText() );
155         action.setToolTipText( this.getText() );
156     }
157
158
159     /**
160      * Returns the text for this action.
161      * <p>
162      * This method is associated with the <code>TEXT</code> property;
163      * property change events are reported when its value changes.
164      * </p>
165      *
166      * @return the text, or <code>null</code> if none
167      * @see #TEXT
168      */

169     public abstract String JavaDoc getText();
170
171
172     /**
173      * Returns the image for this action as an image descriptor.
174      * <p>
175      * This method is associated with the <code>IMAGE</code> property;
176      * property change events are reported when its value changes.
177      * </p>
178      *
179      * @return the image, or <code>null</code> if this action has no image
180      * @see #IMAGE
181      */

182     public abstract ImageDescriptor getImageDescriptor();
183
184
185     /**
186      * Returns the command identifier.
187      *
188      * @return
189      * the command identifier
190      */

191     public abstract String JavaDoc getCommandId();
192
193
194     /**
195      * Returns whether this action is enabled.
196      * <p>
197      * This method is associated with the <code>ENABLED</code> property;
198      * property change events are reported when its value changes.
199      * </p>
200      *
201      * @return <code>true</code> if enabled, and
202      * <code>false</code> if disabled
203      * @see #ENABLED
204      */

205     public abstract boolean isEnabled();
206
207
208     /**
209      * Runs this action.
210      * Each action implementation must define the steps needed to carry out this action.
211      * The default implementation of this method in <code>Action</code>
212      * does nothing.
213      */

214     public abstract void run();
215
216
217     /**
218      * Initializes this action
219      */

220     private void init()
221     {
222         this.selectedConnections = new IConnection[0];
223         this.selectedBrowserViewCategories = new BrowserCategory[0];
224         this.selectedEntries = new IEntry[0];
225         this.selectedBrowserEntryPages = new BrowserEntryPage[0];
226         this.selectedSearches = new ISearch[0];
227         this.selectedSearchResults = new ISearchResult[0];
228         this.selectedBrowserSearchResultPages = new BrowserSearchResultPage[0];
229         this.selectedBookmarks = new IBookmark[0];
230         this.selectedAttributes = new IAttribute[0];
231         this.selectedAttributeHierarchies = new AttributeHierarchy[0];
232         this.selectedValues = new IValue[0];
233
234         this.selectedLdifModel = null;
235         this.selectedLdifContainers = new LdifContainer[0];
236         this.selectedLdifParts = new LdifPart[0];
237
238         this.input = null;
239     }
240
241
242     /**
243      * {@inheritDoc}
244      */

245     public void dispose()
246     {
247         this.selectedConnections = new IConnection[0];
248         this.selectedBrowserViewCategories = new BrowserCategory[0];
249         this.selectedEntries = new IEntry[0];
250         this.selectedBrowserEntryPages = new BrowserEntryPage[0];
251         this.selectedSearches = new ISearch[0];
252         this.selectedSearchResults = new ISearchResult[0];
253         this.selectedBrowserSearchResultPages = new BrowserSearchResultPage[0];
254         this.selectedBookmarks = new IBookmark[0];
255         this.selectedAttributes = new IAttribute[0];
256         this.selectedAttributeHierarchies = new AttributeHierarchy[0];
257         this.selectedValues = new IValue[0];
258
259         this.selectedLdifModel = null;
260         this.selectedLdifContainers = new LdifContainer[0];
261         this.selectedLdifParts = new LdifPart[0];
262
263         this.input = null;
264     }
265
266
267     /**
268      * Returns the current active shell
269      *
270      * @return
271      * the current active shell
272      */

273     protected Shell getShell()
274     {
275         return PlatformUI.getWorkbench().getDisplay().getActiveShell();
276     }
277
278
279     /**
280      * This method is fired when an Entry is updated.
281      *
282      * @param event
283      * the associated event
284      */

285     public final void entryUpdated( EntryModificationEvent event )
286     {
287     }
288
289
290     /**
291      * This method is fired when a Search is updated.
292      *
293      * @param searchUpdateEvent
294      * the associated event
295      */

296     public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
297     {
298     }
299
300
301     /**
302      * This method is fired when a Bookmark is updated.
303      *
304      * @param bookmarkUpdateEvent
305      * the associated event
306      */

307     public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent )
308     {
309     }
310
311
312     /**
313      * This method is fired when a Connection is updated.
314      *
315      * @param connectionUpdateEvent
316      * the associated event
317      */

318     public final void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
319     {
320     }
321
322
323     /**
324      * Gets the selected Attributes.
325      *
326      * @return
327      * the selected attributes
328      */

329     public IAttribute[] getSelectedAttributes()
330     {
331         return selectedAttributes;
332     }
333
334
335     /**
336      * Sets the selected Attributes.
337      *
338      * @param selectedAttributes
339      * the selected attributes to set
340      */

341     public void setSelectedAttributes( IAttribute[] selectedAttributes )
342     {
343         this.selectedAttributes = selectedAttributes;
344     }
345
346
347     /**
348      * Gets the selected Bookmarks.
349      *
350      * @return
351      * the selected Bookmarks
352      */

353     public IBookmark[] getSelectedBookmarks()
354     {
355         return selectedBookmarks;
356     }
357
358
359     /**
360      * Sets the selected Bookmarks.
361      *
362      * @param selectedBookmarks
363      * the selected Bookmarks to set
364      */

365     public void setSelectedBookmarks( IBookmark[] selectedBookmarks )
366     {
367         this.selectedBookmarks = selectedBookmarks;
368     }
369
370
371     /**
372      * Gets the selected Browser View categories.
373      *
374      * @return
375      * the selected Browser View categories
376      */

377     public BrowserCategory[] getSelectedBrowserViewCategories()
378     {
379         return selectedBrowserViewCategories;
380     }
381
382
383     /**
384      * Sets the selected Browser View categories.
385      *
386      * @param selectedBrowserViewCategories
387      * the selected Browser View categories to set
388      */

389     public void setSelectedBrowserViewCategories( BrowserCategory[] selectedBrowserViewCategories )
390     {
391         this.selectedBrowserViewCategories = selectedBrowserViewCategories;
392     }
393
394
395     /**
396      * Gets the selected Connections.
397      *
398      * @return
399      * the selected Connections
400      */

401     public IConnection[] getSelectedConnections()
402     {
403         return selectedConnections;
404     }
405
406
407     /**
408      * Sets the selected Connections.
409      *
410      * @param selectedConnections
411      * the selected Connections to set
412      */

413     public void setSelectedConnections( IConnection[] selectedConnections )
414     {
415         this.selectedConnections = selectedConnections;
416     }
417
418
419     /**
420      * Get the selected Entries.
421      *
422      * @return
423      */

424     public IEntry[] getSelectedEntries()
425     {
426         return selectedEntries;
427     }
428
429
430     /**
431      * Sets the selected Entries.
432      *
433      * @param selectedEntries
434      * the selected Entries to set
435      */

436     public void setSelectedEntries( IEntry[] selectedEntries )
437     {
438         this.selectedEntries = selectedEntries;
439     }
440
441
442     /**
443      * Gets the selected Searches.
444      *
445      * @return
446      * the selected Searches
447      */

448     public ISearch[] getSelectedSearches()
449     {
450         return selectedSearches;
451     }
452
453
454     /**
455      * Sets the selected Searches.
456      *
457      * @param selectedSearches
458      * the selected Searches to set
459      */

460     public void setSelectedSearches( ISearch[] selectedSearches )
461     {
462         this.selectedSearches = selectedSearches;
463     }
464
465
466     /**
467      * Gets the selected Search Results.
468      *
469      * @return
470      * the selected Search Results
471      */

472     public ISearchResult[] getSelectedSearchResults()
473     {
474         return selectedSearchResults;
475     }
476
477
478     /**
479      * Sets the selected Search Results.
480      *
481      * @param selectedSearchResults
482      * the selected Search Results to set
483      */

484     public void setSelectedSearchResults( ISearchResult[] selectedSearchResults )
485     {
486         this.selectedSearchResults = selectedSearchResults;
487     }
488
489
490     /**
491      * Gets the selected Values.
492      *
493      * @return
494      * the selected Values
495      */

496     public IValue[] getSelectedValues()
497     {
498         return selectedValues;
499     }
500
501
502     /**
503      * Sets the selected Values.
504      *
505      * @param selectedValues
506      * the selected values to set
507      */

508     public void setSelectedValues( IValue[] selectedValues )
509     {
510         this.selectedValues = selectedValues;
511     }
512
513
514     /**
515      * Gets the input.
516      *
517      * @return
518      * the input
519      */

520     public Object JavaDoc getInput()
521     {
522         return input;
523     }
524
525
526     /**
527      * Sets the input.
528      *
529      * @param input
530      * the input to set
531      */

532     public void setInput( Object JavaDoc input )
533     {
534         this.input = input;
535     }
536
537
538     /**
539      * Gets the selected LDIF Containers.
540      *
541      * @return
542      * the selected LDIF Containers
543      */

544     public LdifContainer[] getSelectedLdifContainers()
545     {
546         return selectedLdifContainers;
547     }
548
549
550     /**
551      * Sets the selected LDIF Containers.
552      *
553      * @param selectedLdifContainers
554      * the selected LDIF Containers to set
555      */

556     public void setSelectedLdifContainers( LdifContainer[] selectedLdifContainers )
557     {
558         this.selectedLdifContainers = selectedLdifContainers;
559     }
560
561
562     /**
563      * Gets the selected LDIF Model.
564      *
565      * @return
566      * the selected LDIF Model
567      */

568     public LdifFile getSelectedLdifModel()
569     {
570         return selectedLdifModel;
571     }
572
573
574     /**
575      * Sets the selected LDIF Model.
576      *
577      * @param selectedLdifModel
578      * the selected LDIF Model to set
579      */

580     public void setSelectedLdifModel( LdifFile selectedLdifModel )
581     {
582         this.selectedLdifModel = selectedLdifModel;
583     }
584
585
586     /**
587      * Gets the selected LDIF Parts.
588      *
589      * @return
590      * the selected LDIF Parts
591      */

592     public LdifPart[] getSelectedLdifParts()
593     {
594         return selectedLdifParts;
595     }
596
597
598     /**
599      * Sets the selected LDIF Parts.
600      *
601      * @param selectedLdifParts
602      * the selected LDIF Parts to set
603      */

604     public void setSelectedLdifParts( LdifPart[] selectedLdifParts )
605     {
606         this.selectedLdifParts = selectedLdifParts;
607     }
608
609
610     /**
611      * Gets the selected Browser Entry Pages.
612      *
613      * @return
614      * the selected Browser Entru Pages
615      */

616     public BrowserEntryPage[] getSelectedBrowserEntryPages()
617     {
618         return selectedBrowserEntryPages;
619     }
620
621
622     /**
623      * Sets the selected Browser Entry Pages.
624      *
625      * @param selectedBrowserEntryPages
626      * the selected Browser Entry Pages to set
627      */

628     public void setSelectedBrowserEntryPages( BrowserEntryPage[] selectedBrowserEntryPages )
629     {
630         this.selectedBrowserEntryPages = selectedBrowserEntryPages;
631     }
632
633
634     /**
635      * Gets the selected Browser Search Result Pages.
636      *
637      * @return
638      * the selected Browser Search Result Pages
639      */

640     public BrowserSearchResultPage[] getSelectedBrowserSearchResultPages()
641     {
642         return selectedBrowserSearchResultPages;
643     }
644
645
646     /**
647      * Sets the selected Browser Search Result Pages.
648      *
649      * @param selectedBrowserSearchResultPages
650      * the selected Browser Search result Pages to set
651      */

652     public void setSelectedBrowserSearchResultPages( BrowserSearchResultPage[] selectedBrowserSearchResultPages )
653     {
654         this.selectedBrowserSearchResultPages = selectedBrowserSearchResultPages;
655     }
656
657
658     /**
659      * Gets the selected Attribute Hierarchies.
660      *
661      * @return
662      * the selected Attribute Hierarchies
663      */

664     public AttributeHierarchy[] getSelectedAttributeHierarchies()
665     {
666         return selectedAttributeHierarchies;
667     }
668
669
670     /**
671      * Sets the selected Attribute Hierarchies.
672      *
673      * @param ahs
674      * the selected Attribute Hierarchies to set
675      */

676     public void setSelectedAttributeHierarchies( AttributeHierarchy[] ahs )
677     {
678         this.selectedAttributeHierarchies = ahs;
679     }
680 }
681
Popular Tags