analyseWriter/src/action/actDeleteNode.java
pablo rodriguez b40b6edb05 MAJ V4.2.2
Ajout dans le menu structure de l'évaluation dans toutes les page de
l'absence ou la présence de paragraphe vide
2023-02-05 17:46:02 +01:00

110 lines
4.5 KiB
Java

package action;
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.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
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) {
JPanel myPanel = new JPanel();
JLabel message1 = new JLabel("Voulez-vous supprimer ce node ?");
JLabel message2 = new JLabel(fenetres.create.getSelectNode().toString());
myPanel.add(message1);
myPanel.add(message2);
// a spacer
int result = JOptionPane.showConfirmDialog(null, myPanel, "Suppression d'un node", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_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);
}else {
JOptionPane.showMessageDialog(null,"Vous ne devez pas supprimer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
}
}
// 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);
//
//
// }else {
// JOptionPane.showMessageDialog(null,"Vous ne devez pas supprimer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
//
// }
//
// }
}
}
}