Add custom property editor for Office Installation path

This commit is contained in:
Tomas O'Connor
2003-02-24 11:53:43 +00:00
parent f1664b337a
commit 5766a1c300
3 changed files with 57 additions and 6 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: OfficeSettingsBeanInfo.java,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:38 $
* last change: $Author: toconnor $ $Date: 2003-02-24 12:53:43 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,12 +62,18 @@
package org.openoffice.netbeans.modules.office.options;
import java.awt.Image;
import java.awt.Component;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.beans.*;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openoffice.idesupport.OfficeInstallation;
import org.openoffice.netbeans.modules.office.wizard.SelectPathPanel;
/** Description of {@link OfficeSettings}.
*
* @author tomaso
@@ -99,6 +105,7 @@ public class OfficeSettingsBeanInfo extends SimpleBeanInfo {
OfficeSettingsBeanInfo.class, "PROP_OfficeDirectory"));
props[0].setShortDescription(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "HINT_OfficeDirectory"));
props[0].setPropertyEditorClass(OfficeDirectoryEditor.class);
props[1].setDisplayName(NbBundle.getMessage(
OfficeSettingsBeanInfo.class, "PROP_WarnBeforeDocDeploy"));
@@ -133,4 +140,38 @@ public class OfficeSettingsBeanInfo extends SimpleBeanInfo {
return Utilities.loadImage("/org/openoffice/netbeans/modules/office/options/OfficeSettingsIcon32.gif");
}
}
public static class OfficeDirectoryEditor extends PropertyEditorSupport
implements ChangeListener {
private SelectPathPanel panel;
public String getAsText () {
return ((OfficeInstallation)getValue()).getPath();
}
public void setAsText (String path) {
OfficeInstallation oi = new OfficeInstallation(path);
if (!oi.supportsFramework())
throw new IllegalArgumentException(path +
" is not a valid Office install");
else
setValue (oi);
}
public Component getCustomEditor() {
panel = new SelectPathPanel();
panel.addChangeListener(this);
return panel.getComponent();
}
public boolean supportsCustomEditor() {
return true;
}
public void stateChanged(ChangeEvent evt) {
setValue(panel.getSelectedPath());
}
}
}

View File

@@ -64,9 +64,9 @@ public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel *
// and uncomment the complicated stuff below.
}
public final void addChangeListener(ChangeListener l) {}
public final void removeChangeListener(ChangeListener l) {}
/*
// public final void addChangeListener(ChangeListener l) {}
// public final void removeChangeListener(ChangeListener l) {}
private final Set listeners = new HashSet(1); // Set<ChangeListener>
public final void addChangeListener(ChangeListener l) {
synchronized (listeners) {
@@ -88,12 +88,16 @@ public class SelectPathPanel implements WizardDescriptor.Panel /* .FinishPanel *
((ChangeListener)it.next()).stateChanged(ev);
}
}
*/
private OfficeInstallation office;
public void setSelectedPath(OfficeInstallation oi) {
this.office = oi;
fireChangeEvent();
}
public OfficeInstallation getSelectedPath() {
return office;
}
// You can use a settings object to keep track of state.

View File

@@ -15,6 +15,7 @@ import javax.swing.JFileChooser;
import org.openide.util.NbBundle;
import org.openoffice.idesupport.SVersionRCFile;
import org.openoffice.idesupport.OfficeInstallation;
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
/** A single panel for a wizard - the GUI portion.
*
@@ -32,6 +33,7 @@ public class SelectPathVisualPanel extends javax.swing.JPanel {
public SelectPathVisualPanel(SelectPathPanel panel) {
this.panel = panel;
initComponents();
OfficeInstallation orig = OfficeSettings.getDefault().getOfficeDirectory();
try {
Enumeration enum = SVersionRCFile.createInstance().getVersions();
@@ -45,6 +47,10 @@ public class SelectPathVisualPanel extends javax.swing.JPanel {
installationsComboBox.addItem("<empty>");
}
if (orig != null) {
installationsComboBox.setSelectedItem(orig);
}
// Provide a name in the title bar.
setName(NbBundle.getMessage(SelectPathVisualPanel.class, "TITLE_SelectPathVisualPanel"));
/*