/
OpenServerManagedFile.java
72 lines (64 loc) · 2.85 KB
/
OpenServerManagedFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************************************
* Copyright (c) 2022 BestSolution.at and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v.2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* BestSolution.at - initial API and implementation
*******************************************************************************/
package org.eclipse.fx.code.compensator.project.jdt.handler;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MStackElement;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.emf.common.util.URI;
import org.eclipse.fx.code.compensator.editor.TextEditor;
import org.eclipse.fx.code.compensator.editor.services.FileIconLookup;
import org.eclipse.fx.code.compensator.model.workbench.Module;
import org.eclipse.fx.code.compensator.model.workbench.Project;
public class OpenServerManagedFile {
@Execute
public void open(
Project project,
EModelService modelService,
EPartService partService,
MPerspective perspective,
FileIconLookup fileLookup,
@Named("projectid") String projectId,
@Named("moduleName") String modulename,
@Named("modulePath") String modulePath) {
System.err.println("RUNNING");
MPartStack element = (MPartStack) modelService.find("org.eclipse.fx.code.compensator.project.partstack.1", perspective);
String url = "jdt:/"+projectId+"/"+modulename+"/"+modulePath;
for( MStackElement p : element.getChildren() ) {
if( url.equals(p.getPersistedState().get(TextEditor.DOCUMENT_URL)) ) {
partService.showPart((MPart)p, PartState.ACTIVATE);
}
}
String moduleRoot = null;
for( Module m : project.getModuleList() ) {
if( m.getName().equals(modulename) ) {
moduleRoot = m.getRootFolderUrl();
}
}
MPart p = modelService.createModelElement(MPart.class);
p.setContributionURI("bundleclass://org.eclipse.fx.code.compensator.editor/org.eclipse.fx.code.compensator.editor.TextEditor");
p.getPersistedState().put(TextEditor.DOCUMENT_URL, url);
p.getPersistedState().put(TextEditor.VCS_URL, moduleRoot + "/" + modulePath);
p.setLabel(URI.createURI(url).lastSegment());
p.setIconURI(fileLookup.getFileIcon(url).toString());
p.setCloseable(true);
p.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
element.getChildren().add(p);
partService.showPart(p, PartState.ACTIVATE);
}
}