IssueZilla 11377 - Cannot deploy scripts to share directory of Office Installations
IssueZilla 11357 - User not warned before creation of language specific directories.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
*
|
||||
* $RCSfile: ParcelZipper.java,v $
|
||||
*
|
||||
* $Revision: 1.5 $
|
||||
* $Revision: 1.6 $
|
||||
*
|
||||
* last change: $Author: toconnor $ $Date: 2003-01-30 16:22:19 $
|
||||
* last change: $Author: toconnor $ $Date: 2003-02-12 12:41:50 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
@@ -563,7 +563,7 @@ public class ParcelZipper
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getParcelLanguage(File file) throws IOException {
|
||||
public String getParcelLanguage(File file) throws IOException {
|
||||
ZipFile zf = new ZipFile(file);
|
||||
ZipEntry ze = zf.getEntry(PARCEL_DESCRIPTOR_XML);
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
*
|
||||
* $RCSfile: DeployParcelAction.java,v $
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
* last change: $Author: toconnor $ $Date: 2003-01-28 20:52:33 $
|
||||
* last change: $Author: toconnor $ $Date: 2003-02-12 12:41:51 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
@@ -61,14 +61,20 @@
|
||||
|
||||
package org.openoffice.netbeans.modules.office.actions;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import org.openide.TopManager;
|
||||
import org.openide.NotifyDescriptor;
|
||||
@@ -78,6 +84,7 @@ import org.openide.util.HelpCtx;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.RequestProcessor;
|
||||
import org.openide.util.actions.*;
|
||||
import org.openide.awt.JMenuPlus;
|
||||
|
||||
import org.openoffice.idesupport.SVersionRCFile;
|
||||
import org.openoffice.idesupport.zip.ParcelZipper;
|
||||
@@ -87,8 +94,14 @@ import org.openoffice.netbeans.modules.office.utils.NagDialog;
|
||||
import org.openoffice.netbeans.modules.office.options.OfficeSettings;
|
||||
|
||||
public class DeployParcelAction extends CookieAction implements Presenter.Popup {
|
||||
|
||||
private static final String BROWSE_LABEL = "Office Document...";
|
||||
private static final String DEPLOY_LABEL = "Deploy To";
|
||||
private Hashtable offices;
|
||||
private Hashtable mappings;
|
||||
|
||||
public String getName () {
|
||||
return "Deploy To";
|
||||
return DEPLOY_LABEL;
|
||||
}
|
||||
|
||||
public HelpCtx getHelpCtx () {
|
||||
@@ -96,11 +109,79 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup
|
||||
}
|
||||
|
||||
public JMenuItem getPopupPresenter() {
|
||||
return new LocationsMenu (this, new LocationsModel (this), true);
|
||||
JMenuPlus menu = new JMenuPlus(DEPLOY_LABEL);
|
||||
JMenuItem item, user, share;
|
||||
|
||||
try {
|
||||
offices = SVersionRCFile.createInstance().getVersions();
|
||||
mappings = new Hashtable(offices.size());
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JMenuItem item = (JMenuItem)e.getSource();
|
||||
String label = item.getText();
|
||||
|
||||
Node[] nodes = getActivatedNodes();
|
||||
final ParcelCookie parcelCookie =
|
||||
(ParcelCookie)nodes[0].getCookie(ParcelCookie.class);
|
||||
|
||||
File target = new File((String)mappings.get(item) +
|
||||
File.separator + label + File.separator + "Scripts");
|
||||
|
||||
File langdir = new File(target, parcelCookie.getLanguage());
|
||||
|
||||
if (!langdir.exists()) {
|
||||
boolean response = askIfCreateDirectory(langdir);
|
||||
if (response == false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
deploy(target);
|
||||
}
|
||||
};
|
||||
|
||||
Enumeration enum = offices.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String s = (String)enum.nextElement();
|
||||
|
||||
user = new JMenuItem("user");
|
||||
user.addActionListener(listener);
|
||||
mappings.put(user, offices.get(s));
|
||||
|
||||
share = new JMenuItem("share");
|
||||
share.addActionListener(listener);
|
||||
mappings.put(share, offices.get(s));
|
||||
|
||||
item = new JMenuPlus(s);
|
||||
item.add(user);
|
||||
item.add(share);
|
||||
menu.add(item);
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
item = new JMenuItem(BROWSE_LABEL);
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File target = getTargetFile();
|
||||
if (target == null)
|
||||
return;
|
||||
deploy(target);
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
return menu;
|
||||
|
||||
// return new LocationsMenu (this, new LocationsModel (this), true);
|
||||
}
|
||||
|
||||
protected int mode () {
|
||||
return MODE_ALL;
|
||||
return MODE_ONE;
|
||||
}
|
||||
|
||||
protected Class[] cookieClasses () {
|
||||
@@ -111,8 +192,110 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup
|
||||
// do nothing, should not happen
|
||||
}
|
||||
|
||||
private void deploy(final File target) {
|
||||
Node[] nodes = getActivatedNodes();
|
||||
final ParcelCookie parcelCookie =
|
||||
(ParcelCookie)nodes[0].getCookie(ParcelCookie.class);
|
||||
|
||||
RequestProcessor.getDefault().post(new Runnable() {
|
||||
public void run() {
|
||||
boolean result = parcelCookie.deploy(target);
|
||||
|
||||
if (result == true && target.isDirectory()) {
|
||||
showNagDialog();
|
||||
// refreshOffice((String)versions.get(label));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean askIfCreateDirectory(File directory) {
|
||||
String message = directory.getAbsolutePath() + " does not exist. " +
|
||||
"Do you want to create it now?";
|
||||
|
||||
NotifyDescriptor d = new NotifyDescriptor.Confirmation(
|
||||
message, NotifyDescriptor.OK_CANCEL_OPTION);
|
||||
TopManager.getDefault().notify(d);
|
||||
|
||||
if (d.getValue() == NotifyDescriptor.CANCEL_OPTION)
|
||||
return false;
|
||||
|
||||
boolean result;
|
||||
try {
|
||||
result = directory.mkdirs();
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result == false) {
|
||||
String tmp = "Error creating: " + directory.getAbsolutePath();
|
||||
NotifyDescriptor d2 = new NotifyDescriptor.Message(
|
||||
tmp, NotifyDescriptor.ERROR_MESSAGE);
|
||||
TopManager.getDefault().notify(d2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void refreshOffice(String path) {
|
||||
ClassLoader syscl = TopManager.getDefault().currentClassLoader();
|
||||
LocalOffice office = LocalOffice.create(syscl, path, 8100);
|
||||
office.refreshStorage("file://" + path + "/program/../user");
|
||||
office.disconnect();
|
||||
}
|
||||
|
||||
private void showNagDialog() {
|
||||
String message = "If you currently have Office running you will " +
|
||||
"need to click on the Tools/Refresh Scripts menu item " +
|
||||
"in Office so that the scripts in this parcel can be " +
|
||||
"detected.";
|
||||
|
||||
OfficeSettings settings = OfficeSettings.getDefault();
|
||||
|
||||
if (settings.getWarnAfterDirDeploy() == true) {
|
||||
NagDialog warning = NagDialog.createInformationDialog(
|
||||
message, "Show this message in future", true);
|
||||
|
||||
warning.show();
|
||||
|
||||
if (warning.getState() == false)
|
||||
settings.setWarnAfterDirDeploy(false);
|
||||
}
|
||||
}
|
||||
|
||||
private File getTargetFile() {
|
||||
File target = null;
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setDialogTitle("Deploy Parcel To Office Document");
|
||||
chooser.setApproveButtonText("Deploy");
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
chooser.setFileFilter(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory() ||
|
||||
file.getName().endsWith(".sxw") ||
|
||||
file.getName().endsWith(".sxc") ||
|
||||
file.getName().endsWith(".sxi"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Office Documents";
|
||||
}
|
||||
});
|
||||
|
||||
int result = chooser.showDialog(null, null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
target = chooser.getSelectedFile();
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/** Special submenu which notifies model when it is added as a component.
|
||||
*/
|
||||
/*
|
||||
private static final class LocationsMenu extends Actions.SubMenu {
|
||||
|
||||
private final LocationsModel model;
|
||||
@@ -127,14 +310,15 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup
|
||||
super.addNotify ();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/** Model to use for the submenu.
|
||||
*/
|
||||
/*
|
||||
private static final class LocationsModel implements Actions.SubMenuModel {
|
||||
private List labels = null;
|
||||
private Hashtable versions = null;
|
||||
private final NodeAction action;
|
||||
private String BROWSE_LABEL = "Office Document...";
|
||||
|
||||
LocationsModel (NodeAction action) {
|
||||
this.action = action;
|
||||
@@ -219,95 +403,11 @@ public class DeployParcelAction extends CookieAction implements Presenter.Popup
|
||||
labels.add(null);
|
||||
}
|
||||
|
||||
private boolean askIfCreateDirectory(File directory) {
|
||||
String message = "Your Office installation does not have a " +
|
||||
"directory for scripts written in java. Do you want to " +
|
||||
"create one now?";
|
||||
|
||||
NotifyDescriptor d = new NotifyDescriptor.Confirmation(
|
||||
message, NotifyDescriptor.OK_CANCEL_OPTION);
|
||||
TopManager.getDefault().notify(d);
|
||||
|
||||
if (d.getValue() == NotifyDescriptor.CANCEL_OPTION)
|
||||
return false;
|
||||
|
||||
boolean result;
|
||||
try {
|
||||
result = directory.mkdirs();
|
||||
}
|
||||
catch (SecurityException se) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result == false) {
|
||||
String tmp = "Error creating: " + directory.getAbsolutePath();
|
||||
NotifyDescriptor d2 = new NotifyDescriptor.Message(
|
||||
tmp, NotifyDescriptor.ERROR_MESSAGE);
|
||||
TopManager.getDefault().notify(d2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void refreshOffice(String path) {
|
||||
ClassLoader syscl = TopManager.getDefault().currentClassLoader();
|
||||
LocalOffice office = LocalOffice.create(syscl, path, 8100);
|
||||
office.refreshStorage("file://" + path + "/program/../user");
|
||||
office.disconnect();
|
||||
}
|
||||
|
||||
private void showNagDialog() {
|
||||
String message = "If you currently have Office running you will " +
|
||||
"need to click on the Tools/Refresh Scripts(java) menu item " +
|
||||
"in Office so that the scripts in this parcel can be " +
|
||||
"detected.";
|
||||
|
||||
OfficeSettings settings = OfficeSettings.getDefault();
|
||||
|
||||
if (settings.getWarnAfterDirDeploy() == true) {
|
||||
NagDialog warning = NagDialog.createInformationDialog(
|
||||
message, "Show this message in future", true);
|
||||
|
||||
warning.show();
|
||||
|
||||
if (warning.getState() == false)
|
||||
settings.setWarnAfterDirDeploy(false);
|
||||
}
|
||||
}
|
||||
|
||||
private File getTargetFile() {
|
||||
File target = null;
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setDialogTitle("Deploy Parcel To Office Document");
|
||||
chooser.setApproveButtonText("Deploy");
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
chooser.setFileFilter(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory() ||
|
||||
file.getName().endsWith(".sxw") ||
|
||||
file.getName().endsWith(".sxc") ||
|
||||
file.getName().endsWith(".sxi"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Office Documents";
|
||||
}
|
||||
});
|
||||
|
||||
int result = chooser.showDialog(null, null);
|
||||
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
target = chooser.getSelectedFile();
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public synchronized void addChangeListener (ChangeListener l) {
|
||||
}
|
||||
|
||||
public synchronized void removeChangeListener (ChangeListener l) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
*
|
||||
* $RCSfile: ParcelCookie.java,v $
|
||||
*
|
||||
* $Revision: 1.2 $
|
||||
* $Revision: 1.3 $
|
||||
*
|
||||
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:23 $
|
||||
* last change: $Author: toconnor $ $Date: 2003-02-12 12:41:51 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
@@ -68,6 +68,8 @@ public interface ParcelCookie extends Node.Cookie
|
||||
{
|
||||
public File getFile();
|
||||
|
||||
public String getLanguage();
|
||||
|
||||
public void mount();
|
||||
|
||||
public boolean deploy(File target);
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
*
|
||||
* $RCSfile: ParcelSupport.java,v $
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
* last change: $Author: toconnor $ $Date: 2003-01-28 20:52:34 $
|
||||
* last change: $Author: toconnor $ $Date: 2003-02-12 12:41:51 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
@@ -91,6 +91,7 @@ public class ParcelSupport implements ParcelCookie
|
||||
{
|
||||
private FileObject fo;
|
||||
private ParcelZipper zipper = ParcelZipper.getParcelZipper();
|
||||
private String language = null;
|
||||
|
||||
public ParcelSupport(FileObject fo) {
|
||||
this.fo = fo;
|
||||
@@ -100,6 +101,18 @@ public class ParcelSupport implements ParcelCookie
|
||||
return FileUtil.toFile(fo);
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
if (language == null) {
|
||||
try {
|
||||
language = zipper.getParcelLanguage(getFile());
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
public void mount()
|
||||
{
|
||||
File parcel = FileUtil.toFile(fo);
|
||||
|
||||
Reference in New Issue
Block a user