KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > view > WelcomeView


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.view;
22
23
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import org.apache.directory.ldapstudio.Messages;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.events.SelectionAdapter;
31 import org.eclipse.swt.events.SelectionEvent;
32 import org.eclipse.swt.graphics.Font;
33 import org.eclipse.swt.graphics.Image;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Button;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.ui.PartInitException;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.part.ViewPart;
42
43
44 /**
45  * This class defines the Welcome View.
46  *
47  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
48  * @version $Rev$, $Date$
49  */

50 public class WelcomeView extends ViewPart
51 {
52     public static final String JavaDoc ID = "org.apache.directory.ldapstudio.view.WelcomeView"; //$NON-NLS-1$
53

54     /* (non-Javadoc)
55      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
56      */

57     public void createPartControl( Composite parent )
58     {
59         Composite container = new Composite( parent, SWT.NULL );
60         GridLayout layout = new GridLayout( 2, true );
61         container.setLayout( layout );
62
63         // Welcome Label
64
Label welcomeLabel = new Label( container, SWT.CENTER );
65         welcomeLabel.setFont( new Font( null, "Georgia", 13, SWT.BOLD ) ); //$NON-NLS-1$
66
welcomeLabel.setText( Messages.getString( "WelcomeView.Welcome_message" ) ); //$NON-NLS-1$
67
welcomeLabel.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true, 2, 1 ) );
68
69         // LDAP Browser Plugin Image & Button
70
Image ldapBrowserImage = new Image( PlatformUI.getWorkbench().getDisplay(), getClass().getResourceAsStream(
71             "ldapstudio_ldap-browser-plugin.png" ) ); //$NON-NLS-1$
72
Button ldapBrowserButton = new Button( container, SWT.FLAT );
73         ldapBrowserButton.setImage( ldapBrowserImage );
74         ldapBrowserButton.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false ) );
75         ldapBrowserButton.addSelectionListener( new SelectionAdapter()
76         {
77             public void widgetSelected( SelectionEvent e )
78             {
79                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(
80                     PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(
81                         "org.apache.directory.ldapstudio.browser.ui.perspective.BrowserPerspective" ) ); //$NON-NLS-1$
82
}
83         } );
84
85         // Schemas Editor Plugin Image & Button
86
Image schemasEditorImage = new Image( PlatformUI.getWorkbench().getDisplay(), getClass().getResourceAsStream(
87             "ldapstudio_schemas-editor-plugin.png" ) ); //$NON-NLS-1$
88
Button schemasEditorButton = new Button( container, SWT.FLAT );
89         schemasEditorButton.setImage( schemasEditorImage );
90         schemasEditorButton.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false ) );
91         schemasEditorButton.addSelectionListener( new SelectionAdapter()
92         {
93             public void widgetSelected( SelectionEvent e )
94             {
95                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(
96                     PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(
97                         "org.apache.directory.ldapstudio.schemas.perspective" ) ); //$NON-NLS-1$
98
}
99         } );
100
101         // LDAP Browser Plugin Label
102
Label ldapBrowserLabel = new Label( container, SWT.NONE );
103         ldapBrowserLabel.setFont( new Font( null, "Georgia", 13, SWT.BOLD ) ); //$NON-NLS-1$
104
ldapBrowserLabel.setText( Messages.getString("WelcomeView.LDAP_Browser_Plugin") ); //$NON-NLS-1$
105
ldapBrowserLabel.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, true, true ) );
106
107         // Schemas Editor Plugin Label
108
Label schemasEditorLabel = new Label( container, SWT.NONE );
109         schemasEditorLabel.setFont( new Font( null, "Georgia", 13, SWT.BOLD ) ); //$NON-NLS-1$
110
schemasEditorLabel.setText( Messages.getString("WelcomeView.Schemas_Editor_Plugin") ); //$NON-NLS-1$
111
schemasEditorLabel.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, true, true ) );
112
113         // Apache Software Foundation Image
114
Image asfLogoImange = new Image( PlatformUI.getWorkbench().getDisplay(), getClass().getResourceAsStream(
115             "asf-logo.gif" ) ); //$NON-NLS-1$
116
Button asfLogoButton = new Button( container, SWT.FLAT );
117         asfLogoButton.setImage( asfLogoImange );
118         asfLogoButton.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false, 2, 1 ) );
119         asfLogoButton.addSelectionListener( new SelectionAdapter()
120         {
121             public void widgetSelected( SelectionEvent e )
122             {
123                 try
124                 {
125                     PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(
126                         new URL JavaDoc( Messages.getString("WelcomeView.Apache.org_url") ) ); //$NON-NLS-1$
127
}
128                 catch ( PartInitException e1 )
129                 {
130                     // Displaying an error
131
MessageDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
132                         Messages.getString("WelcomeView.Error"), Messages.getString("WelcomeView.LDAP_Studio_was_unable_to_open_www.apache.org") ); //$NON-NLS-1$ //$NON-NLS-2$
133
}
134                 catch ( MalformedURLException JavaDoc e1 )
135                 {
136                     // Will never be thrown
137
}
138             }
139         } );
140
141         // Copyright Label
142
Label copyrightLabel = new Label( container, SWT.NONE );
143         copyrightLabel.setText( Messages.getString("WelcomeView.Copyright") ); //$NON-NLS-1$
144
copyrightLabel.setLayoutData( new GridData( SWT.CENTER, SWT.NONE, false, false, 2, 1 ) );
145     }
146
147     
148     /* (non-Javadoc)
149      * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
150      */

151     public void setFocus()
152     {
153         // Does nothing but needed
154
}
155 }
Popular Tags