|
31 | 31 | import org.eclipse.core.commands.ExecutionEvent; |
32 | 32 | import org.eclipse.core.commands.ExecutionException; |
33 | 33 | import org.eclipse.core.resources.IFile; |
34 | | -import org.eclipse.core.resources.IMarker; |
35 | 34 | import org.eclipse.core.resources.IProject; |
36 | 35 | import org.eclipse.core.resources.IResource; |
37 | 36 | import org.eclipse.core.runtime.CoreException; |
|
50 | 49 |
|
51 | 50 | public class DockerizeHandler extends AzureAbstractHandler { |
52 | 51 |
|
| 52 | + private static final String DEFAULT_TEXT_EDITOR = "org.eclipse.ui.DefaultTextEditor"; |
| 53 | + |
53 | 54 | @Override |
54 | 55 | public Object onExecute(ExecutionEvent event) throws ExecutionException { |
55 | | - IProject project = PluginUtil.getSelectedProject(); |
| 56 | + final IProject project = PluginUtil.getSelectedProject(); |
56 | 57 | ConsoleLogger.info(Constant.MESSAGE_ADDING_DOCKER_SUPPORT); |
57 | 58 | EventUtil.executeWithLog(WEBAPP, CREATE_DOCKER_FILE, (operation) -> { |
58 | 59 | if (project == null) { |
59 | 60 | throw new Exception(Constant.ERROR_NO_SELECTED_PROJECT); |
60 | 61 | } |
61 | | - String basePath = project.getLocation().toString(); |
| 62 | + final String basePath = project.getLocation().toString(); |
62 | 63 | String dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT; |
63 | 64 | String artifactRelativePath = Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER; |
64 | 65 | if (MavenUtils.isMavenProject(project)) { |
@@ -92,16 +93,20 @@ public Object onExecute(ExecutionEvent event) throws ExecutionException { |
92 | 93 | } |
93 | 94 |
|
94 | 95 | private void openFile(IFile file) { |
95 | | - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
96 | | - IWorkbenchPage page = window.getActivePage(); |
97 | | - IMarker marker; |
| 96 | + final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
| 97 | + final IWorkbenchPage page = window.getActivePage(); |
98 | 98 | try { |
99 | | - marker = file.createMarker(IMarker.TEXT); |
100 | | - IDE.openEditor(page, marker); |
101 | | - marker.delete(); |
102 | | - |
| 99 | + if (isDefaultTextEditorExists(page)) { |
| 100 | + IDE.openEditor(page, file, "org.eclipse.ui.DefaultTextEditor"); |
| 101 | + } else { |
| 102 | + IDE.openEditor(page, file); |
| 103 | + } |
103 | 104 | } catch (CoreException e) { |
104 | 105 | e.printStackTrace(); |
105 | 106 | } |
106 | 107 | } |
| 108 | + |
| 109 | + private boolean isDefaultTextEditorExists(IWorkbenchPage page) { |
| 110 | + return page.getWorkbenchWindow().getWorkbench().getEditorRegistry().findEditor(DEFAULT_TEXT_EDITOR) != null; |
| 111 | + } |
107 | 112 | } |
0 commit comments