2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.eclipse.webapp.internal.ui;
22  
23  import org.apache.cactus.eclipse.webapp.internal.Webapp;
24  import org.eclipse.core.resources.IProject;
25  import org.eclipse.core.runtime.CoreException;
26  import org.eclipse.core.runtime.IAdaptable;
27  import org.eclipse.jdt.core.IJavaProject;
28  import org.eclipse.jdt.core.JavaCore;
29  import org.eclipse.jface.preference.PreferencePage;
30  import org.eclipse.swt.widgets.Composite;
31  import org.eclipse.swt.widgets.Control;
32  import org.eclipse.ui.IWorkbench;
33  import org.eclipse.ui.IWorkbenchPreferencePage;
34  import org.eclipse.ui.dialogs.PropertyPage;
35  import org.eclipse.ui.internal.dialogs.WorkbenchPreferencePage;
36  
37  /**
38   * Property page for the web application.
39   * It is displayed in project's property pages.
40   * 
41   * @version $Id: WebAppPropertyPage.java 238816 2004-02-29 16:36:46Z vmassol $
42   */
43  public class WebAppPropertyPage extends PropertyPage
44  {
45      /**
46       * The only UI block for this property page. 
47       */
48      private WebAppConfigurationBlock webAppConfigurationBlock;
49  
50      /**
51       * The webapp object that is loaded or persisted. 
52       */
53      private Webapp webapp;
54  
55      /**
56       * @see org.eclipse.jface.preference.PreferencePage#createContents(
57       *     org.eclipse.swt.widgets.Composite)
58       */
59      protected final Control createContents(final Composite theParent)
60      {
61          IJavaProject javaProject = JavaCore.create(getProject());
62          webapp = new Webapp(javaProject);
63          webapp.init();
64  
65          // TODO: Status line indicating we loaded the defaults 
66  //        boolean loadedDefaults = webapp.init();
67  //        if (loadedDefaults)
68  //        {
69  //        }
70  
71          webAppConfigurationBlock =
72              new WebAppConfigurationBlock(
73                  getShell(),
74                  javaProject,
75                  webapp.getOutput(),
76                  webapp.getDir(),
77                  webapp.getClasspath());
78          return webAppConfigurationBlock.createContents(theParent);
79      }
80  
81      /**
82       * @see org.eclipse.jface.preference.PreferencePage#performOk()
83       */
84      public final boolean performOk()
85      {
86          webapp.setOutput(webAppConfigurationBlock.getOutput());
87          webapp.setDir(webAppConfigurationBlock.getWebappDir());
88          webapp.setClasspath(webAppConfigurationBlock.getWebappClasspath());
89          try
90          {
91              webapp.persist();
92          }
93          catch (CoreException e)
94          {
95              //TODO: update status line
96              System.err.println(e.getStackTrace());
97          	  e.printStackTrace();
98              return false;
99          }
100         return true;
101     }
102 
103     /**
104      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
105      */
106     public final void performDefaults()
107     {
108         super.performDefaults();
109         webapp.loadDefaultValues();
110         webAppConfigurationBlock.update(
111             webapp.getOutput(),
112             webapp.getDir(),
113             webapp.getClasspath());
114         webAppConfigurationBlock.refresh();
115     }
116 
117     /**
118      * Returns the project on which this property page has been called.
119      * @return the current project
120      */
121     private IProject getProject()
122     {
123     	
124         IAdaptable adaptable = getElement();
125         IProject elem = (IProject) adaptable.getAdapter(IProject.class);
126         return elem;
127         
128         //return getProject();
129     }
130 
131 	public void init(IWorkbench arg0) {
132 		// TODO Auto-generated method stub
133 		setPreferenceStore(WebappPlugin.getDefault().getPreferenceStore());
134 		
135 		
136 	}
137 }