KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > schemabrowser > SchemaBrowserManager


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.schemabrowser;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
26 import org.eclipse.ui.PartInitException;
27 import org.eclipse.ui.PlatformUI;
28
29
30 /**
31  * The SchemaBrowserManager is used to set and get the the input
32  * of the single schema browser instance.
33  *
34  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
35  * @version $Rev$, $Date$
36  */

37 public class SchemaBrowserManager
38 {
39
40     /** The dummy input, to find the single schema browser instance */
41     private static SchemaBrowserInput DUMMY_INPUT = new SchemaBrowserInput( null, null );
42
43
44     /**
45      * Sets the input to the schema browser.
46      *
47      * @param connection the connection
48      * @param schemaElement the schema element
49      */

50     public static void setInput( IConnection connection, SchemaPart schemaElement )
51     {
52         SchemaBrowserInput input = new SchemaBrowserInput( connection, schemaElement );
53         setInput( input );
54     }
55
56
57     /**
58      * Sets the input to the schema browser.
59      *
60      * @param input the input
61      */

62     private static void setInput( SchemaBrowserInput input )
63     {
64         SchemaBrowser editor = ( SchemaBrowser ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
65             .findEditor( DUMMY_INPUT );
66         if ( editor == null && input != null )
67         {
68             // open new schema browser
69
try
70             {
71                 editor = ( SchemaBrowser ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
72                     .openEditor( input, SchemaBrowser.getId(), false );
73                 editor.setInput( input );
74             }
75             catch ( PartInitException e )
76             {
77                 e.printStackTrace();
78             }
79         }
80         else if ( editor != null )
81         {
82             // set the input to already opened schema browser
83
editor.setInput( input );
84
85             // bring schema browser to top only if a schema element should be displayed.
86
if ( input.getSchemaElement() != null )
87             {
88                 if ( !PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().isPartVisible( editor ) )
89                 {
90                     PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().bringToTop( editor );
91                 }
92             }
93         }
94     }
95
96 }
97
Popular Tags