1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with 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,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  
23  
24  package org.openoffice.netbeans.modules.office.options;
25  
26  import java.awt.Image;
27  import java.awt.Component;
28  import javax.swing.event.ChangeListener;
29  import javax.swing.event.ChangeEvent;
30  import java.beans.*;
31  
32  import org.openide.ErrorManager;
33  import org.openide.util.NbBundle;
34  import org.openide.util.Utilities;
35  
36  import org.openoffice.idesupport.OfficeInstallation;
37  import org.openoffice.netbeans.modules.office.wizard.SelectPathPanel;
38  
39  /** Description of {@link OfficeSettings}.
40   *
41   * @author tomaso
42   */
43  public class OfficeSettingsBeanInfo extends SimpleBeanInfo {
44  
getPropertyDescriptors()45      public PropertyDescriptor[] getPropertyDescriptors() {
46          try {
47              PropertyDescriptor[] props = new PropertyDescriptor[] {
48                  new PropertyDescriptor(OfficeSettings.OFFICE_DIRECTORY,
49                                 OfficeSettings.class,
50                                 "get" + OfficeSettings.OFFICE_DIRECTORY,
51                                 "set" + OfficeSettings.OFFICE_DIRECTORY),
52                  new PropertyDescriptor(OfficeSettings.WARN_BEFORE_DOC_DEPLOY,
53                                 OfficeSettings.class,
54                                 "get" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY,
55                                 "set" + OfficeSettings.WARN_BEFORE_DOC_DEPLOY),
56                  new PropertyDescriptor(OfficeSettings.WARN_BEFORE_PARCEL_DELETE,
57                                 OfficeSettings.class,
58                                 "get" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE,
59                                 "set" + OfficeSettings.WARN_BEFORE_PARCEL_DELETE),
60                  new PropertyDescriptor(OfficeSettings.WARN_AFTER_DIR_DEPLOY,
61                                 OfficeSettings.class,
62                                 "get" + OfficeSettings.WARN_AFTER_DIR_DEPLOY,
63                                 "set" + OfficeSettings.WARN_AFTER_DIR_DEPLOY),
64                  new PropertyDescriptor(OfficeSettings.WARN_BEFORE_MOUNT,
65                                 OfficeSettings.class,
66                                 "get" + OfficeSettings.WARN_BEFORE_MOUNT,
67                                 "set" + OfficeSettings.WARN_BEFORE_MOUNT)
68              };
69  
70              props[0].setDisplayName(NbBundle.getMessage(
71                  OfficeSettingsBeanInfo.class, "PROP_OfficeDirectory"));
72              props[0].setShortDescription(NbBundle.getMessage(
73                  OfficeSettingsBeanInfo.class, "HINT_OfficeDirectory"));
74              props[0].setPropertyEditorClass(OfficeDirectoryEditor.class);
75  
76              props[1].setDisplayName(NbBundle.getMessage(
77                  OfficeSettingsBeanInfo.class, "PROP_WarnBeforeDocDeploy"));
78              props[1].setShortDescription(NbBundle.getMessage(
79                  OfficeSettingsBeanInfo.class, "HINT_WarnBeforeDocDeploy"));
80              props[1].setHidden(true);
81  
82              props[2].setDisplayName(NbBundle.getMessage(
83                  OfficeSettingsBeanInfo.class, "PROP_WarnAfterDirDeploy"));
84              props[2].setShortDescription(NbBundle.getMessage(
85                  OfficeSettingsBeanInfo.class, "HINT_WarnAfterDirDeploy"));
86              props[2].setHidden(true);
87  
88              props[3].setDisplayName(NbBundle.getMessage(
89                  OfficeSettingsBeanInfo.class, "PROP_WarnBeforeMount"));
90              props[3].setShortDescription(NbBundle.getMessage(
91                  OfficeSettingsBeanInfo.class, "HINT_WarnBeforeMount"));
92              props[3].setHidden(true);
93  
94              return props;
95          }
96          catch (IntrospectionException ie) {
97              ErrorManager.getDefault().notify(ie);
98              return null;
99          }
100      }
101  
getIcon(int type)102      public Image getIcon(int type) {
103          if (type == BeanInfo.ICON_COLOR_16x16 || type == BeanInfo.ICON_MONO_16x16) {
104              return Utilities.loadImage("/org/openoffice/netbeans/modules/office/options/OfficeSettingsIcon.gif");
105          } else {
106              return Utilities.loadImage("/org/openoffice/netbeans/modules/office/options/OfficeSettingsIcon32.gif");
107          }
108      }
109  
110      public static class OfficeDirectoryEditor extends PropertyEditorSupport
111          implements ChangeListener {
112  
113          private SelectPathPanel panel;
114  
getAsText()115          public String getAsText () {
116              return ((OfficeInstallation)getValue()).getPath();
117          }
118  
setAsText(String path)119          public void setAsText (String path) {
120              OfficeInstallation oi = new OfficeInstallation(path);
121  
122              if (!oi.supportsFramework())
123                  throw new IllegalArgumentException(path +
124                      " is not a valid Office install");
125              else
126                  setValue (oi);
127          }
128  
getCustomEditor()129          public Component getCustomEditor() {
130              panel = new SelectPathPanel();
131              panel.addChangeListener(this);
132              return panel.getComponent();
133          }
134  
supportsCustomEditor()135          public boolean supportsCustomEditor() {
136              return true;
137          }
138  
stateChanged(ChangeEvent evt)139          public void stateChanged(ChangeEvent evt) {
140              setValue(panel.getSelectedPath());
141          }
142      }
143  }
144