Skip to content

Commit fa81440

Browse files
authored
Open docker file with text editor by default (#4569)
* Open docker file with text editor by default * Fix checkstyle
1 parent b8901c4 commit fa81440

File tree

1 file changed

+15
-10
lines changed
  • PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.container/src/main/java/com/microsoft/azuretools/container/handlers

1 file changed

+15
-10
lines changed

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.container/src/main/java/com/microsoft/azuretools/container/handlers/DockerizeHandler.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.eclipse.core.commands.ExecutionEvent;
3232
import org.eclipse.core.commands.ExecutionException;
3333
import org.eclipse.core.resources.IFile;
34-
import org.eclipse.core.resources.IMarker;
3534
import org.eclipse.core.resources.IProject;
3635
import org.eclipse.core.resources.IResource;
3736
import org.eclipse.core.runtime.CoreException;
@@ -50,15 +49,17 @@
5049

5150
public class DockerizeHandler extends AzureAbstractHandler {
5251

52+
private static final String DEFAULT_TEXT_EDITOR = "org.eclipse.ui.DefaultTextEditor";
53+
5354
@Override
5455
public Object onExecute(ExecutionEvent event) throws ExecutionException {
55-
IProject project = PluginUtil.getSelectedProject();
56+
final IProject project = PluginUtil.getSelectedProject();
5657
ConsoleLogger.info(Constant.MESSAGE_ADDING_DOCKER_SUPPORT);
5758
EventUtil.executeWithLog(WEBAPP, CREATE_DOCKER_FILE, (operation) -> {
5859
if (project == null) {
5960
throw new Exception(Constant.ERROR_NO_SELECTED_PROJECT);
6061
}
61-
String basePath = project.getLocation().toString();
62+
final String basePath = project.getLocation().toString();
6263
String dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
6364
String artifactRelativePath = Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER;
6465
if (MavenUtils.isMavenProject(project)) {
@@ -92,16 +93,20 @@ public Object onExecute(ExecutionEvent event) throws ExecutionException {
9293
}
9394

9495
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();
9898
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+
}
103104
} catch (CoreException e) {
104105
e.printStackTrace();
105106
}
106107
}
108+
109+
private boolean isDefaultTextEditorExists(IWorkbenchPage page) {
110+
return page.getWorkbenchWindow().getWorkbench().getEditorRegistry().findEditor(DEFAULT_TEXT_EDITOR) != null;
111+
}
107112
}

0 commit comments

Comments
 (0)