Project

General

Profile

« Previous | Next » 

Revision 2dc06490

Added by Patrick Plitzner almost 6 years ago

fix #3161 Term editors open as singletons

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/OpenDefinedTermEditorHandlerE4.java
8 8
 */
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.definedterm.e4.handler;
11
import java.util.List;
11 12
import java.util.UUID;
13
import java.util.stream.Collectors;
12 14

  
13 15
import org.eclipse.e4.core.di.annotations.Execute;
14 16
import org.eclipse.e4.ui.model.application.MApplication;
......
39 41
	    String commandId = menuItem.getCommand().getElementId();
40 42
        UUID termTypeUuid = (UUID) menuItem.getTransientData().get(commandId+".termTypeUuid");
41 43

  
42
		TermEditorInput termEditorInput = new TermEditorInput(TermType.getByUuid(termTypeUuid));
43
		MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
44
		MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
45
		if(editorAreaPartStack!=null){
46
		    editorAreaPartStack.getChildren().add(part);
44
		TermType termType = TermType.getByUuid(termTypeUuid);
45
        TermEditorInput termEditorInput = new TermEditorInput(termType);
46
		List<MPart> alreadyOpenedEditors = partService.getParts().stream()
47
		.filter(part->part.getObject()!=null && part.getObject() instanceof DefinedTermEditorE4)
48
		.filter(part->((DefinedTermEditorE4)part.getObject()).getDefinedTermEditorInput().getTermType().equals(termType))
49
		.collect(Collectors.toList());
50
		if(!alreadyOpenedEditors.isEmpty()){
51
		    //there should never be more than one already opened editor
52
		    //so we just open the first
53
		    partService.activate(alreadyOpenedEditors.iterator().next());
54
		}
55
		else{
56
		    MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
57
		    MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
58
		    if(editorAreaPartStack!=null){
59
		        editorAreaPartStack.getChildren().add(part);
60
		    }
61
		    part = partService.showPart(part, PartState.ACTIVATE);
62
		    DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
63
		    termEditor.init(termEditorInput);
47 64
		}
48
		part = partService.showPart(part, PartState.ACTIVATE);
49
		DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
50
		termEditor.init(termEditorInput);
51 65
	}
52 66

  
53 67
}

Also available in: Unified diff