Project

General

Profile

Revision 1cb71588

ID1cb715888edfbfde0655060092b9f83378fcfc55
Parent 3fb2dd8d
Child 2406537d

Added by Patrick Plitzner about 3 years ago

Fix potential NPE when opening entities that have already been deleted

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorUtil.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
11 11

  
12 12
import org.eclipse.core.commands.operations.IOperationHistory;
13 13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.Assert;
15 14
import org.eclipse.ui.IEditorInput;
16 15
import org.eclipse.ui.IEditorPart;
17 16
import org.eclipse.ui.PartInitException;
......
21 20
import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputType;
22 21
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
23 22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24 24

  
25 25
/**
26 26
 * <p>BulkEditorUtil class.</p>
......
30 30
 * @version 1.0
31 31
 */
32 32
public class BulkEditorUtil extends AbstractUtility{
33
	
33

  
34 34
	/**
35 35
	 * Opens a new editor window with the given input
36
	 * 
36
	 *
37 37
	 * @param input
38 38
	 * @param editorId
39
	 * @return 
39
	 * @return
40 40
	 * @throws PartInitException
41 41
	 */
42 42
	private static IEditorPart open(IEditorInput input, String editorId)
43 43
			throws PartInitException {
44 44
		return getActivePage().openEditor(input, editorId);
45 45
	}
46
	
46

  
47 47
	/**
48 48
	 * <p>openEmptyEditor</p>
49 49
	 *
......
54 54
		AbstractBulkEditorInput editorInput = AbstractBulkEditorInput.NewInstance(inputType);
55 55
		open(editorInput, BulkEditor.ID);
56 56
	}
57
	
57

  
58 58
	/**
59 59
	 * <p>openEditor</p>
60 60
	 *
......
62 62
	 * @throws org.eclipse.ui.PartInitException if any.
63 63
	 */
64 64
	public static void openEditor(IdentifiableEntity entity) throws PartInitException{
65
		Assert.isNotNull(entity, "Entity must not be null");
65
	    if(entity==null){
66
	        MessagingUtils.errorDialog("Entity does not exist", BulkEditorUtil.class, "The entity does not exist in the data base. Maybe it has been deleted.", TaxeditorBulkeditorPlugin.PLUGIN_ID, null, false, false);
67
	        return;
68
	    }
66 69
		AbstractBulkEditorInput editorInput = AbstractBulkEditorInput.NewInstance(entity);
67 70
		open(editorInput, BulkEditor.ID);
68 71
	}
69
	
72

  
70 73
	/**
71 74
	 * <p>getPluginId</p>
72 75
	 *
......
75 78
	public static String getPluginId(){
76 79
		return TaxeditorBulkeditorPlugin.PLUGIN_ID;
77 80
	}
78
	
81

  
79 82
	/**
80 83
	 * <p>getUndoContext</p>
81 84
	 *
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerContextMenu.java
75 75
                        				menuItem.addSelectionListener(new CommandInvoker(command, firstElement)) ;
76 76
                        			}
77 77
                        		}
78
                        		else{
79
                        		    MenuItem addItem = new MenuItem(menu, SWT.CASCADE);
80
                        		    addItem.setText("No viewers available");
81
                        		    addItem.setEnabled(false);
82
                        		}
78 83
                        	}
79 84
                        }
80 85
                    }
......
95 100

  
96 101
        @Override
97 102
        public void widgetSelected(SelectionEvent e) {
98
            IHandlerService handlerService = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
103
            IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
99 104
            Map<String, UUID> params = new HashMap<String, UUID>();
100 105
            //for generic UuidAndTitleCache objects try to load the object
101 106
            if (selectedObject instanceof UuidAndTitleCache){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/CdmViewerUtil.java
54 54
                TreeNode treeNode = (TreeNode)input;
55 55
                input = treeNode.getValue();
56 56
            }
57

  
58

  
57
            if(input==null){
58
                return commandViewerNameMap;
59
            }
59 60
            IExtensionRegistry reg = Platform.getExtensionRegistry();
60 61
            IConfigurationElement[] extensions = reg
61 62
                    .getConfigurationElementsFor("eu.etaxonomy.taxeditor.store.cdmViewer"); //$NON-NLS-1$

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)