/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.project;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JPopupMenu;
import com.jstatcom.component.CompSettings;
import com.jstatcom.component.StdMessages;
/**
* Popup menu that is invoked when right clicking on a project tree node. Can be
* used to edit existing projects and to manage tree nodes themselves.
*
* @author Markus Kraetzig
*/
public final class ProjectNodePopup extends JPopupMenu {
/**
* Saves the current state to the project represented by the underlying tree
* node.
*/
private AbstractAction save = new AbstractAction("Save Current State Here") {
public void actionPerformed(ActionEvent evt) {
ProjectManager.getInstance().serializeProject(
currentNode.getProjectFile(), currentNode.getName(),
currentNode.getDescription());
}
};
/**
* Deletes the tree node and optionally the project file as well.
*/
private AbstractAction delete = new AbstractAction("Delete") {
public void actionPerformed(ActionEvent evt) {
ProjectTree.getInstance().deleteSelectedProjects();
}
};
/**
* Invokes a dialog to edit all properties of the project corresponding to
* the underlying project tree node.
*/
private AbstractAction edit = new AbstractAction("Edit") {
public void actionPerformed(ActionEvent evt) {
if (currentNode == null)
return;
try {
getProjectDialog().setProjectNode(currentNode);
getProjectDialog().setSaveDialog(false);
getProjectDialog().setVisible(true);
} catch (Throwable ex) {
String msg = "There was an error loading the project from\n\""
+ currentNode.getProjectFile()
+ "\"\nThe message was:\n" + ex.getMessage();
StdMessages.error(msg, "Project Edit Error");
}
// rest is handled by project dialog on OK
}
};
/**
* Displays project information in a dialog.
*/
private AbstractAction info = new AbstractAction("Project Info") {
public void actionPerformed(ActionEvent evt) {
if (currentNode == null)
return;
String msg = "Name:\n";
msg = msg + currentNode.getName() + "\n\n";
msg = msg + "Last edited:\n";
msg = msg
+ CompSettings.getDefaultDateFormat().format(
currentNode.getDate()) + "\n\n";
msg = msg + "File:\n";
msg = msg + currentNode.getProjectFile() + "\n\n";
msg = msg + "Description:\n";
msg = msg + currentNode.getDescription();
StdMessages.info(msg, "Project Information");
}
};
/**
* Singleton instance.
*/
private static final ProjectNodePopup INSTANCE = new ProjectNodePopup();
/**
* Currently selected node.
*/
private ProjectTreeNode currentNode = null;
/**
* Not to be invoked.
*/
private ProjectNodePopup() {
super();
add(save);
addSeparator();
add(edit);
add(delete);
addSeparator();
add(info);
}
private ProjectDialog getProjectDialog() {
return ProjectDialog.getInstance();
}
/**
* Gets the singleton instance of this popup menu.
*
* @return initialized shared instance
*/
public static ProjectNodePopup getInstance() {
return INSTANCE;
}
/**
* Sets the project node that should be referenced by actions invoked from
* this component. Should be set by the project tree.
*
* @param currentNode
* current project tree node
*/
public void setCurrentNode(ProjectTreeNode currentNode) {
boolean lastState = currentNode.isLastState();
save.setEnabled(!lastState);
edit.setEnabled(!lastState);
this.currentNode = currentNode;
}
} // @jve:decl-index=0:visual-constraint="71,93"
Ads help maintain this website.