~tapaal-contributor/tapaal/places-with-same-name-shared-1801728

« back to all changes in this revision

Viewing changes to src/pipe/gui/widgets/TAPNTransitionEditor.java

  • Committer: ptaankvist at gmail
  • Date: 2019-01-31 17:18:34 UTC
  • Revision ID: ptaankvist@gmail.com-20190131171834-awgxte0hew50qj2i
Works for transitions as well as places

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
22
22
import dk.aau.cs.gui.Context;
23
23
import dk.aau.cs.gui.undo.Command;
 
24
import dk.aau.cs.gui.undo.MakePlaceNewSharedMultiCommand;
24
25
import dk.aau.cs.gui.undo.MakeTransitionNewSharedCommand;
 
26
import dk.aau.cs.gui.undo.MakeTransitionNewSharedMultiCommand;
25
27
import dk.aau.cs.gui.undo.MakeTransitionSharedCommand;
26
28
import dk.aau.cs.gui.undo.RenameTimedTransitionCommand;
27
29
import dk.aau.cs.gui.undo.ToggleTransitionUrgent;
388
390
 
389
391
        private boolean okButtonHandler(java.awt.event.ActionEvent evt) {
390
392
                String newName = nameTextField.getText();
 
393
                System.out.println("Hej");
391
394
                
392
395
                // Check urgent constrain
393
396
                if(urgentCheckBox.isSelected() && !isUrgencyOK()){
402
405
                        transition.underlyingTransition().unshare();
403
406
                }
404
407
                
405
 
                if(sharedCheckBox.isSelected()){        
 
408
                if(sharedCheckBox.isSelected() && !(transition.underlyingTransition().isShared())){     
 
409
                        System.out.println(transition.underlyingTransition().isShared() + " " + sharedCheckBox.isSelected());
406
410
                        SharedTransition selectedTransition = (SharedTransition)sharedTransitionsComboBox.getSelectedItem();
407
 
                        Command command = new MakeTransitionSharedCommand(context.activeModel(), selectedTransition, transition.underlyingTransition(), context.tabContent());
 
411
            Command command = new MakeTransitionSharedCommand(context.activeModel(), selectedTransition, transition.underlyingTransition(), context.tabContent());
408
412
                        context.undoManager().addEdit(command);
409
413
                        try{
410
414
                                command.redo();
438
442
                        context.nameGenerator().updateIndices(transition.underlyingTransition().model(), newName);
439
443
                        
440
444
                        if(makeNewShared){
441
 
                                Command command = new MakeTransitionNewSharedCommand(context.activeModel(), newName, transition.underlyingTransition(), context.tabContent());
 
445
                                Command command = new MakeTransitionNewSharedCommand(context.activeModel(), newName, transition.underlyingTransition(), context.tabContent(), false);
442
446
                                context.undoManager().addEdit(command);
443
447
                                try{
444
448
                                        command.redo();
445
449
                                }catch(RequireException e){
 
450
                                        System.out.println(makeSharedButton.isEnabled() + " " + sharedCheckBox.isSelected());
446
451
                                        context.undoManager().undo();
447
 
                                        JOptionPane.showMessageDialog(this,"A transition or place with the specified name already exists, or the specified name is invalid.\n\nAcceptable names are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*", "Error", JOptionPane.ERROR_MESSAGE);
448
 
                                        return false;
 
452
                                        int dialogResult = JOptionPane.showConfirmDialog(this, "A transition or place with the specified name already exists, or the specified name is invalid.\n\nAcceptable names for transitions are defined by the regular expression:\n[a-zA-Z][_a-zA-Z0-9]*\n\nNote that \"true\" and \"false\" are reserved keywords. \n\n Would you like to make the other transitions of the same name shared too?", "Error", JOptionPane.YES_NO_OPTION);
 
453
                                        if(dialogResult == JOptionPane.YES_OPTION) {
 
454
                                                Command cmd = new MakeTransitionNewSharedMultiCommand(context, newName, transition);    
 
455
                                                cmd.redo();
 
456
                                                context.undoManager().addNewEdit(cmd);
 
457
                                        } else
 
458
                                                return false;
449
459
                                }
450
460
                                transition.setUrgent(urgentCheckBox.isSelected());
451
461
                        }