Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open docker file with text editor by default #4569

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}