import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.ObjectInputStream;
import java.net.URL;
import java.net.URLConnection;
+/**
+ * Applet providing a set of buttons. Each button is defined by three parameters:<BR>
+ * <ul>
+ * <li><i>icon<i></i></li>
+ * <li><i>tool<i></i></li>
+ * <li><i>file<i></i></li> - may be null
+ * </ul>
+ * where i is an index beginning from zero.
+ */
public class ToolbarApplet extends java.applet.Applet implements ActionListener {
+ /**
+ * Serialization version id.
+ */
private static final long serialVersionUID = 3243053622061086715L;
// ==============================================================================================================================
// Overridden functions
// ==============================================================================================================================
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.applet.Applet#init()
+ */
@Override
public void init() {
URL appurl = getCodeBase();
applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
public void actionPerformed(final ActionEvent event) {
- // -----------------------------------------------
if (event.getSource() instanceof ToolButton) {
ToolButton clicked = (ToolButton) event.getSource();
String module = clicked.getTool();
// Public member functions
// ==============================================================================================================================
+ /**
+ * Launch an appropriate application for the given file.
+ *
+ * @param name
+ * module name
+ * @param filename
+ * file name
+ */
public void launch(final String name, final String filename) {
- // -------------------------------------------------
String module = name;
try {
} else
// Opening an application on the local machine
+
+ if (module.equals("runSalome")) {
+ // Run SALOME
+ // To get the SALOME_HOME environment variable
+ String SALOME_HOME = System.getenv("SALOME_ROOT_DIR");
+ // If SALOME_ROOT_DIR does not exist the SALOME_HOME equals to null.
+ if (SALOME_HOME == null) {
+ // TODO: Use logger to be more user friendly
+ getAppletContext()
+ .showDocument(
+ new URL(
+ getCodeBase().toString()
+ + "error.jsp?message=launch&value="
+ + "SALOME_ROOT_DIR environment variable is not defined."),
+ "_blank");
+ throw new Exception(
+ "SALOME_ROOT_DIR nevironment variable is not defined.");
+ } else if (!SALOME_HOME.endsWith(File.separator)) {
+ SALOME_HOME += File.separator;
+ }
+ String pathToScript = SALOME_HOME + "runSalome";
+
+ File script = new File(pathToScript);
+ if (!script.exists()) {
+ script = new File(pathToScript + ".bat");
+ if (!script.exists()) {
+ script = new File(pathToScript + ".cmd");
+ }
+ }
+
+ if (script.exists()) {
+ // Execute the runSalome script.
+ // filename here indeed a string containing parameters for runSalome.
+ Runtime.getRuntime().exec(
+ new String[] { script.getAbsolutePath(), filename });
+ } else {
+ // TODO: Use logger to be more user friendly
+ getAppletContext().showDocument(
+ new URL(getCodeBase().toString()
+ + "error.jsp?message=launch&value="
+ + "SALOME module is not found: "
+ + script.getAbsolutePath()), "_blank");
+ throw new FileNotFoundException(
+ "SALOME module is not found: " + script.getAbsolutePath());
+ }
+ } else
+
if (module.endsWith(".exe") || module.endsWith(".EXE")) {
String applikey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Applications\\"
+ module;
super("create");
addItem("new-empty", "menu.new.empty", "image.empty.png",
"select?menu=create&item=new-empty");
- addItem("new-copy", new MenuItem("menu.new.copy")
- .icon("image.copy.png"));
- addItem("new-instance", new MenuItem("menu.new.instance")
- .icon(IMG_HOLD));
- addItem("new-import", new MenuItem("menu.new.import")
- .icon("icon.upload.png"));
+ addItem("new-copy",
+ new MenuItem("menu.new.copy").icon("image.copy.png"));
+ addItem("new-instance",
+ new MenuItem("menu.new.instance").icon(IMG_HOLD));
+ addItem("new-import",
+ new MenuItem("menu.new.import").icon("icon.upload.png"));
this.selects("new-empty");
}
}
"select?menu=search&item=search-study");
addItem("search-knowledge", "menu.search.idea", "image.idea.png",
"select?menu=search&item=search-knowledge");
- addItem("search-document", new MenuItem("menu.search.document")
- .icon("icon.any.png"));
+ addItem("search-document",
+ new MenuItem("menu.search.document").icon("icon.any.png"));
this.selects("search-study");
}
}
"select?menu=datadmin&item=admin-scontext");
addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
"select?menu=datadmin&item=admin-knowelm");
- addItem("admin-study", new MenuItem("menu.admin.study")
- .icon("image.study.png"));
+ addItem("admin-study",
+ new MenuItem("menu.admin.study").icon("image.study.png"));
}
}
private EditableStudyPopup() {
super();
- addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
- "image.publish.png").action("edit-study?action=publish")
- .confirmation("message.publish.study"));
+ addItem(MNU_PUBLISH,
+ new PopupItem(MNU_NAME_PUBLISH).icon("image.publish.png")
+ .action("edit-study?action=publish")
+ .confirmation("message.publish.study"));
addItem(MNU_PROMOTE, new PopupItem("menu.archive"));
addSeparator();
- addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
- "icon.ed.png").action("../select?menu=properties"));
+ addItem(MNU_EDIT,
+ new PopupItem("menu.properties").icon("icon.ed.png")
+ .action("../select?menu=properties"));
addSeparator();
- addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
- .action("add-scenario"));
- addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
- IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
+ addItem(MNU_SCRIPT,
+ new PopupItem(MNU_NAME_SCRIPT).action("add-scenario"));
+ addItem(MNU_VERSION,
+ new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
+ ACT_NOT_YET_IMPLEMENTED));
addSeparator();
- addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE)
- .confirmation("message.purge.study"));
- addItem("export", new PopupItem("menu.export")
- .icon("image.export.png")); // For future needs
- addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
- .action(ACT_NOT_YET_IMPLEMENTED).confirmation(
- "message.delete.study"));
+ addItem(MNU_PURGE,
+ new PopupItem(MNU_NAME_PURGE)
+ .confirmation("message.purge.study"));
+ addItem("export",
+ new PopupItem("menu.export").icon("image.export.png")); // For future needs
+ addItem(MNU_REMOVE,
+ new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
+ .action(ACT_NOT_YET_IMPLEMENTED)
+ .confirmation("message.delete.study"));
}
@Override
private EditableDocumentPopup() {
super();
- addItem("accept", new PopupItem("menu.accept").icon(
- "image.accept.png").action("setDocument?action=accept")
- .confirmation("message.accept.document"));
- addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
- "image.publish.png").action("setDocument?action=promote")
- .confirmation("message.promote.document"));
+ addItem("accept",
+ new PopupItem("menu.accept").icon("image.accept.png")
+ .action("setDocument?action=accept")
+ .confirmation("message.accept.document"));
+ addItem(MNU_PROMOTE,
+ new PopupItem(MNU_NAME_PROMOTE).icon("image.publish.png")
+ .action("setDocument?action=promote")
+ .confirmation("message.promote.document"));
addSeparator();
- addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
- .action("edit-document?action=renameDocument"));
+ addItem(MNU_RENAME,
+ new PopupItem(MNU_NAME_RENAME)
+ .action("edit-document?action=renameDocument"));
addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
.action(ACT_ATTACH));
addSeparator();
- addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
- IMG_VERSION).action(ACT_VERSION));
- addItem("replace", new PopupItem("menu.replace").icon(
- "image.replace.png").action(
- "select-file?nextAction=replace"));
+ addItem(MNU_VERSION,
+ new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
+ ACT_VERSION));
+ addItem("replace",
+ new PopupItem("menu.replace").icon("image.replace.png")
+ .action("select-file?nextAction=replace"));
addSeparator();
- addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
- ACT_NOT_YET_IMPLEMENTED).confirmation(
- "message.purge.document"));
- addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
- .action("remove-document").confirmation(
- "message.delete.document"));
+ addItem(MNU_PURGE,
+ new PopupItem(MNU_NAME_PURGE).action(
+ ACT_NOT_YET_IMPLEMENTED).confirmation(
+ "message.purge.document"));
+ addItem(MNU_REMOVE,
+ new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
+ .action("remove-document")
+ .confirmation("message.delete.document"));
}
@Override
private ReviewableDocumentPopup() {
super();
- addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
- "image.demote.png").action("setDocument?action=demote")
- .confirmation("message.demote.document"));
- addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
- "image.review.png").action("setDocument?action=review")
- .confirmation("message.review.document"));
+ addItem(MNU_DEMOTE,
+ new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png")
+ .action("setDocument?action=demote")
+ .confirmation("message.demote.document"));
+ addItem(MNU_PROMOTE,
+ new PopupItem("menu.review").icon("image.review.png")
+ .action("setDocument?action=review")
+ .confirmation("message.review.document"));
addSeparator();
addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
.action(ACT_ATTACH));
addSeparator();
- addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
- IMG_VERSION).action(ACT_VERSION));
+ addItem(MNU_VERSION,
+ new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
+ ACT_VERSION));
addSeparator();
- addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
- ACT_NOT_YET_IMPLEMENTED).confirmation(
- "message.purge.document"));
+ addItem(MNU_PURGE,
+ new PopupItem(MNU_NAME_PURGE).action(
+ ACT_NOT_YET_IMPLEMENTED).confirmation(
+ "message.purge.document"));
}
@Override
private NotResultDocumentPopup() {
super();
- addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
- "image.demote.png").action("setDocument?action=demote")
- .confirmation("message.demote.document"));
+ addItem(MNU_DEMOTE,
+ new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png")
+ .action("setDocument?action=demote")
+ .confirmation("message.demote.document"));
addSeparator();
addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
.action(ACT_ATTACH));
addSeparator();
- addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
- IMG_VERSION).action(ACT_VERSION));
+ addItem(MNU_VERSION,
+ new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
+ ACT_VERSION));
addSeparator();
- addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
- ACT_NOT_YET_IMPLEMENTED).confirmation(
- "message.purge.document"));
- addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
- .action("remove-document").confirmation(
- "message.delete.document"));
+ addItem(MNU_PURGE,
+ new PopupItem(MNU_NAME_PURGE).action(
+ ACT_NOT_YET_IMPLEMENTED).confirmation(
+ "message.purge.document"));
+ addItem(MNU_REMOVE,
+ new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
+ .action("remove-document")
+ .confirmation("message.delete.document"));
}
}
private ApprovableDocumentPopup() {
super();
- addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
- "image.invalidate.png").action(
- "setDocument?action=invalidate").confirmation(
- "message.demote.document"));
- addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
- "image.demote.png").action("setDocument?action=disapprove")
- .confirmation("message.disapprove.document"));
- addItem("approve", new PopupItem("menu.approve").icon(
- "icon.APPROVED.png").action("setDocument?action=approve")
- .confirmation("message.approve.document"));
+ addItem("undo",
+ new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png")
+ .action("setDocument?action=invalidate")
+ .confirmation("message.demote.document"));
+ addItem(MNU_DEMOTE,
+ new PopupItem("menu.disapprove").icon("image.demote.png")
+ .action("setDocument?action=disapprove")
+ .confirmation("message.disapprove.document"));
+ addItem("approve",
+ new PopupItem("menu.approve").icon("icon.APPROVED.png")
+ .action("setDocument?action=approve")
+ .confirmation("message.approve.document"));
}
@Override
addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
.action(ACT_ATTACH));
addSeparator();
- addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
- IMG_VERSION).action(ACT_VERSION));
+ addItem(MNU_VERSION,
+ new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
+ ACT_VERSION));
}
}
private ExternPopup() {
super();
- addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
- .action("edit-document?action=renameDocument"));
- addItem("replace", new PopupItem("menu.replace").icon(
- "image.replace.png").action(
- "select-file?nextAction=replace"));
+ addItem(MNU_RENAME,
+ new PopupItem(MNU_NAME_RENAME)
+ .action("edit-document?action=renameDocument"));
+ addItem("replace",
+ new PopupItem("menu.replace").icon("image.replace.png")
+ .action("select-file?nextAction=replace"));
addSeparator();
- addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
- IMG_DELETE).action("remove-document").confirmation(
- "message.delete.document"));
+ addItem(MNU_REMOVE,
+ new PopupItem("menu.remove.document").icon(IMG_DELETE)
+ .action("remove-document")
+ .confirmation("message.delete.document"));
}
@Override
private ScontextPopup() {
super();
- addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
- .action("edit-context?action=renameContext"));
- addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
- .action("edit-context?action=editContext"));
+ addItem(MNU_RENAME,
+ new PopupItem(MNU_NAME_RENAME)
+ .action("edit-context?action=renameContext"));
+ addItem(MNU_EDIT,
+ new PopupItem(MNU_NAME_EDIT)
+ .action("edit-context?action=editContext"));
addSeparator();
- addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
- .action("remove-context").confirmation(
- "message.delete.context"));
+ addItem(MNU_REMOVE,
+ new PopupItem("menu.remove").icon(IMG_DELETE)
+ .action("remove-context")
+ .confirmation("message.delete.context"));
}
@Override
private FeedbexPopup() {
super();
- addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
- "image.review.png").action("promote-knowledge")
- .confirmation("message.promote.knowledge"));
- addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
- "image.invalidate.png").action("demote-knowledge")
- .confirmation("message.demote.knowledge"));
+ addItem(MNU_PROMOTE,
+ new PopupItem(MNU_NAME_PROMOTE).icon("image.review.png")
+ .action("promote-knowledge")
+ .confirmation("message.promote.knowledge"));
+ addItem(MNU_DEMOTE,
+ new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png")
+ .action("demote-knowledge")
+ .confirmation("message.demote.knowledge"));
addSeparator();
- addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
- .action("edit-knowledge?action=renameKnowledge"));
- addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
- .action("edit-knowledge?action=editKnowledge"));
+ addItem(MNU_RENAME,
+ new PopupItem(MNU_NAME_RENAME)
+ .action("edit-knowledge?action=renameKnowledge"));
+ addItem(MNU_EDIT,
+ new PopupItem(MNU_NAME_EDIT)
+ .action("edit-knowledge?action=editKnowledge"));
addSeparator();
- addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
- .action("remove-knowledge").confirmation(
- "message.delete.knowledge"));
+ addItem(MNU_REMOVE,
+ new PopupItem("menu.remove").icon(IMG_DELETE)
+ .action("remove-knowledge")
+ .confirmation("message.delete.knowledge"));
}
@Override
ToolBar bar = new ToolBar(24); // Height of the module-bar
Set<String> module = new HashSet<String>(); // For not duplicating modules
- for (Iterator<String> j = formats.iterator(); j.hasNext();) {
- String format = j.next();
+ for (String format : formats) {
String command = getApplicationProperty("executable." + format);
if (command == null) {
continue; // Module not installed
} else {
icon = "tool." + icon.toLowerCase() + ".png";
}
- File image = new File(ApplicationSettings
- .getApplicationSkinPath()
- + icon);
+ File image = new File(
+ ApplicationSettings.getApplicationSkinPath() + icon);
if (!image.exists()) {
icon = "tool.any.png";
}
} else {
docname = "/jsp/newDocument.jsp?type=" + docname;
String icon = "tool." + name[0].toLowerCase() + ".png";
- File image = new File(ApplicationSettings
- .getApplicationSkinPath()
- + icon);
+ File image = new File(
+ ApplicationSettings.getApplicationSkinPath() + icon);
if (!image.exists()) {
icon = "tool.any.png";
}
}
public String getApplicationURL() {
- StringBuffer url = new StringBuffer("http://").append(
- MY_APP._wappserver).append("/").append(_wappname);
+ StringBuffer url = new StringBuffer("http://")
+ .append(MY_APP._wappserver).append("/").append(_wappname);
return url.toString();
}
}
public static String getDownloadURL(final User user) {
- StringBuffer url = new StringBuffer("http://").append(
- MY_APP._wappserver).append("/download/").append(
- user.getUsername()).append("/");
+ StringBuffer url = new StringBuffer("http://")
+ .append(MY_APP._wappserver).append("/download/")
+ .append(user.getUsername()).append("/");
return url.toString(); // The download Tomcat context is supposed being defined
}