Skip to content

Commit

Permalink
Open docker file with text editor by default (#4569)
Browse files Browse the repository at this point in the history
* Open docker file with text editor by default

* Fix checkstyle
  • Loading branch information
Flanker32 authored Aug 24, 2020
1 parent b8901c4 commit fa81440
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -50,15 +49,17 @@

public class DockerizeHandler extends AzureAbstractHandler {

private static final String DEFAULT_TEXT_EDITOR = "org.eclipse.ui.DefaultTextEditor";

@Override
public Object onExecute(ExecutionEvent event) throws ExecutionException {
IProject project = PluginUtil.getSelectedProject();
final IProject project = PluginUtil.getSelectedProject();
ConsoleLogger.info(Constant.MESSAGE_ADDING_DOCKER_SUPPORT);
EventUtil.executeWithLog(WEBAPP, CREATE_DOCKER_FILE, (operation) -> {
if (project == null) {
throw new Exception(Constant.ERROR_NO_SELECTED_PROJECT);
}
String basePath = project.getLocation().toString();
final String basePath = project.getLocation().toString();
String dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
String artifactRelativePath = Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER;
if (MavenUtils.isMavenProject(project)) {
Expand Down Expand Up @@ -92,16 +93,20 @@ public Object onExecute(ExecutionEvent event) throws ExecutionException {
}

private void openFile(IFile file) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IMarker marker;
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
try {
marker = file.createMarker(IMarker.TEXT);
IDE.openEditor(page, marker);
marker.delete();

if (isDefaultTextEditorExists(page)) {
IDE.openEditor(page, file, "org.eclipse.ui.DefaultTextEditor");
} else {
IDE.openEditor(page, file);
}
} catch (CoreException e) {
e.printStackTrace();
}
}

private boolean isDefaultTextEditorExists(IWorkbenchPage page) {
return page.getWorkbenchWindow().getWorkbench().getEditorRegistry().findEditor(DEFAULT_TEXT_EDITOR) != null;
}
}

0 comments on commit fa81440

Please sign in to comment.