Project

General

Profile

« Previous | Next » 

Revision f2199620

Added by Patrick Plitzner almost 6 years ago

ref #7010 Allow multiple selection for derivative delete handler

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java
53 53
    private SpecimenDeleteConfigurator deleteConfigurator;
54 54

  
55 55
    @Execute
56
    public Object execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode treeNode, ParameterizedCommand command) {
56
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection, ParameterizedCommand command) {
57 57
        deleteConfigurator = new SpecimenDeleteConfigurator();
58 58
        if(command.getId().equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DERIVATE_DEEPDELETE)){
59 59
            deleteConfigurator.setDeleteChildren(true);
60 60
        }
61

  
62 61
        DerivateView derivateView = (DerivateView) part.getObject();
62

  
63
        String confirmationQuestion = Messages.DeleteDerivateOperation_REALLY_DELETE;
64
        if(deleteConfigurator.isDeleteChildren()){
65
            confirmationQuestion += Messages.DeleteDerivateOperation_AND_CHILDREN;
66
        }
67

  
68
        if(derivateView.isDirty()){
69
            MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
70
            return;
71
        }
72
        confirmationQuestion += "?"; //$NON-NLS-1$
73
        if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, Messages.DeleteDerivateOperation_CONFIRM, confirmationQuestion)){
74
            return;
75
        }
76

  
77
        if(selection instanceof Object[]){
78
            for (Object o : (Object[])selection) {
79
                if(o instanceof TreeNode){
80
                    delete((TreeNode)o, derivateView);
81
                }
82
            }
83
        }
84
        if(selection instanceof TreeNode){
85
            delete((TreeNode)selection, derivateView);
86
        }
87

  
88
    }
89

  
90
    private void delete(TreeNode treeNode, DerivateView derivateView){
63 91
        Object value = treeNode.getValue();
64 92
        IStatus allowStatus = allowOperations(derivateView, treeNode);
65 93
        if(allowStatus.isOK()) {
......
77 105

  
78 106
            if (!deleteResult.isOk()) {
79 107
                MessagingUtils.warningDialog(Messages.DeleteDerivateOperation_DELETE_FAILED, this, deleteResult.toString());
80

  
81
                return Status.CANCEL_STATUS;
108
                return ;
82 109
            }
83 110
            //broadcast delete result
84 111
            EventUtility.postEvent(WorkbenchEventConstants.DELETE_DERIVATIVE, deleteResult);
......
87 114
                derivateView.remove(treeNode);
88 115

  
89 116
            }
90
            return Status.OK_STATUS;
91 117
        }
92
        return null;
118

  
93 119
    }
94 120

  
95 121
    public IStatus allowOperations(DerivateView derivateView, TreeNode treeNode) {
96
        String confirmationQuestion = Messages.DeleteDerivateOperation_REALLY_DELETE;
97
        if(deleteConfigurator.isDeleteChildren()){
98
            confirmationQuestion += Messages.DeleteDerivateOperation_AND_CHILDREN;
99
        }
100

  
101
        if(derivateView.isDirty()){
102
            MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
103
            return Status.CANCEL_STATUS;
104
        }
105
        confirmationQuestion += "?"; //$NON-NLS-1$
106
        if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, Messages.DeleteDerivateOperation_CONFIRM, confirmationQuestion)){
107
            return Status.CANCEL_STATUS;
108
        }
109 122
        DeleteResult deleteResult;
110 123
        Object value = treeNode.getValue();
111 124
        if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){
......
131 144
    }
132 145

  
133 146
    @CanExecute
134
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node,
147
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
135 148
            MHandledMenuItem menuItem){
136
        boolean canExecute = node !=null;
149
        boolean canExecute = false;
150
        canExecute = selection!=null;
137 151
        menuItem.setVisible(canExecute);
138 152
        return canExecute;
139 153
    }

Also available in: Unified diff