70 lines
2.7 KiB
Java
70 lines
2.7 KiB
Java
package fenetres.create_act;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.KeyStroke;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.TreePath;
|
|
|
|
import cXML.node;
|
|
import fenetres.create;
|
|
|
|
public class actDeleteNode extends AbstractAction{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
{
|
|
putValue( Action.NAME, "Supprime" );
|
|
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/supprimemini.png")) );
|
|
putValue( Action.SHORT_DESCRIPTION, "Supprime" );
|
|
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK ) );
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
|
if(fenetres.create.getTree().getSelectionPath()!=null) {
|
|
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous supprimer le node " + fenetres.create.getSelectNode().toString() + "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
|
|
|
|
if(a == JOptionPane.YES_NO_OPTION) {
|
|
node nod = (node) fenetres.create.getSelectNode().getUserObject();
|
|
if(!(nod.getNomElt().equals("setting")||nod.getNomElt().equals("csv")||nod.getNomElt().equals("import_moodle")||nod.getNomElt().equals("zip")
|
|
||nod.getNomElt().equals("plagiarism")||nod.getNomElt().equals("text:similarity")||nod.getNomElt().equals("color") ||nod.getNomElt().equals("translation") )) {
|
|
|
|
nod.getParent().supprimeNodeEnfant(nod);
|
|
|
|
TreePath path = fenetres.create.getTree().getSelectionPath().getParentPath();
|
|
DefaultMutableTreeNode nodMu = fenetres.create.getSelectNode();
|
|
DefaultMutableTreeNode SelectParentNode = (DefaultMutableTreeNode) nodMu.getParent();
|
|
|
|
SelectParentNode.remove(nodMu);
|
|
|
|
DefaultTreeModel model = (DefaultTreeModel) fenetres.create.getTree().getModel();
|
|
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
|
|
model.reload(root);
|
|
|
|
fenetres.create.getTree().setSelectionPath(path);
|
|
fenetres.create.getTree().expandPath(path);
|
|
|
|
// fenetres.create.constructionTree();
|
|
|
|
}else {
|
|
JOptionPane.showMessageDialog(null,"Vous ne devez pas supprimer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|