-
- private class WidgetSelectionListener extends SelectionAdapter{
- private final CommandType commandType;
-
- /**
- * @param selectedTreeNode
- * @param clipboardNode
- * @param commandType
- */
- public WidgetSelectionListener(CommandType commandType) {
- this.commandType = commandType;
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
- final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
- TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeOfSelection(clipBoardSelection);
- TreeNode selectedTreeNode = EditorUtil.getTreeNodeOfSelection(selection);
- switch (commandType) {
- case REMOVE_FROM_SEQUENCE:
- if(activeEditor.isDirty()){
- MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
- return;
- }
- if(selectedTreeNode!=null && selectedTreeNode.getParent()!=null &&
- selectedTreeNode.getValue() instanceof SingleRead && selectedTreeNode.getParent().getValue() instanceof Sequence) {
- Sequence sequence = (Sequence) selectedTreeNode.getParent().getValue();
- sequence.removeSingleRead((SingleRead) selectedTreeNode.getValue());
- CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
- if(activeEditor instanceof DerivateView) {
- DerivateView derivateView = (DerivateView)activeEditor;
- derivateView.getConversationHolder().commit();
- derivateView.refreshTree();
- }
- }
-
- break;
- case ADD_TO_SEQUENCE:
- if(activeEditor.isDirty()){
- MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
- return;
- }
- if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
- && selectedTreeNode!=null && selectedTreeNode.getValue() instanceof Sequence){
- SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
- Sequence sequence = (Sequence)selectedTreeNode.getValue();
- sequence.addSingleRead(singleRead);
- CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
- if(activeEditor instanceof DerivateView) {
- DerivateView derivateView = (DerivateView)activeEditor;
- derivateView.getConversationHolder().commit();
- derivateView.refreshTree();
- LocalSelectionTransfer.getTransfer().setSelection(null);
- }
- }
- break;
- case COPY_TO_CLIPBOARD:
- LocalSelectionTransfer.getTransfer().setSelection(selection);
- break;
- }
- }
- }