2023-02-05 17:46:02 +01:00
package action ;
2022-06-19 21:01:30 +02:00
import java.awt.event.ActionEvent ;
2022-11-22 22:17:32 +01:00
import java.awt.event.KeyEvent ;
2022-06-19 21:01:30 +02:00
import javax.swing.AbstractAction ;
import javax.swing.Action ;
import javax.swing.ImageIcon ;
2022-12-18 14:04:11 +01:00
import javax.swing.JLabel ;
2022-06-19 21:01:30 +02:00
import javax.swing.JOptionPane ;
2022-12-18 14:04:11 +01:00
import javax.swing.JPanel ;
2022-11-22 22:17:32 +01:00
import javax.swing.KeyStroke ;
import javax.swing.tree.DefaultMutableTreeNode ;
import javax.swing.tree.DefaultTreeModel ;
import javax.swing.tree.TreePath ;
2022-06-19 21:01:30 +02:00
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 " ) ;
2022-11-22 22:17:32 +01:00
putValue ( Action . ACCELERATOR_KEY , KeyStroke . getKeyStroke ( KeyEvent . VK_D , KeyEvent . CTRL_DOWN_MASK ) ) ;
2022-06-19 21:01:30 +02:00
}
@Override
public void actionPerformed ( ActionEvent e ) {
if ( fenetres . create . getTree ( ) . getSelectionPath ( ) ! = null ) {
2022-12-18 14:04:11 +01:00
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 ( ) ;
2022-06-19 21:01:30 +02:00
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 ) ;
2022-11-22 22:17:32 +01:00
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 ) ;
2022-06-19 21:01:30 +02:00
} else {
JOptionPane . showMessageDialog ( null , " Vous ne devez pas supprimer ce node ! " , " Oh non!!! " , JOptionPane . INFORMATION_MESSAGE ) ;
}
2022-12-18 14:04:11 +01:00
}
// 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);
//
// }
//
// }
2022-06-19 21:01:30 +02:00
}
}
}