Skip to content

Commit

Permalink
JBIDE-17657: Cmd+4 now uses the shell context directory
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 26, 2014
1 parent 1b57e97 commit 2ddc51a
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 41 deletions.
Expand Up @@ -11,4 +11,5 @@ public interface Console {
void connect(Document document);
void disconnect();

Object getCurrentResource();
}
Expand Up @@ -6,10 +6,15 @@

import org.eclipse.core.resources.ResourcesPlugin;
import org.jboss.forge.addon.projects.ProjectFactory;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.shell.ShellHandle;
import org.jboss.forge.addon.shell.spi.command.CdTokenHandler;
import org.jboss.forge.addon.shell.spi.command.CdTokenHandlerFactory;
import org.jboss.forge.addon.ui.command.AbstractCommandExecutionListener;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.furnace.spi.ListenerRegistration;
import org.jboss.tools.aesh.core.console.AbstractConsole;
import org.jboss.tools.forge.core.furnace.FurnaceService;
Expand All @@ -20,23 +25,35 @@ public class AeshConsole extends AbstractConsole {
private CommandLineListener executionListener = new CommandLineListener();
private ListenerRegistration<CdTokenHandler> tokenHandler;

private Resource<?> currentResource;

public void start() {
handle = FurnaceService.INSTANCE.lookup(ShellHandle.class);
File currentDir = ResourcesPlugin.getWorkspace().getRoot()
ResourceFactory resourceFactory = FurnaceService.INSTANCE
.lookup(ResourceFactory.class);
final File currentDir = ResourcesPlugin.getWorkspace().getRoot()
.getLocation().toFile();
currentResource = resourceFactory.create(currentDir);
OutputStream stdOut = getOutputStream();
OutputStream stdErr = getErrorStream();
PrintStream out = new PrintStream(stdOut, true);
PrintStream err = new PrintStream(stdErr, true);
handle.initialize(currentDir, getInputStream(), out, err);
handle.addCommandExecutionListener(executionListener);
// Listening for selection events
handle.addCommandExecutionListener(new AbstractCommandExecutionListener() {
@Override
public void postCommandExecuted(UICommand command,
UIExecutionContext context, Result result) {
currentResource = context.getUIContext().getSelection();
}
});

ProjectFactory projectFactory = FurnaceService.INSTANCE
.lookup(ProjectFactory.class);
projectFactory.addProjectListener(executionListener);
CdTokenHandlerFactory tokenHandlerFactory = FurnaceService.INSTANCE
.lookup(CdTokenHandlerFactory.class);
ResourceFactory resourceFactory = FurnaceService.INSTANCE
.lookup(ResourceFactory.class);
tokenHandler = tokenHandlerFactory
.addTokenHandler(new WorkspaceCdTokenHandler(resourceFactory));
}
Expand All @@ -49,4 +66,9 @@ public void stop() {
tokenHandler.removeListener();
tokenHandler = null;
}

@Override
public Resource<?> getCurrentResource() {
return currentResource;
}
}
Expand Up @@ -6,21 +6,22 @@
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.ui.internal.viewer.ForgeTextViewer;

public abstract class AbstractForgeConsole
implements ForgeConsole, PropertyChangeListener, DisposeListener {
public abstract class AbstractForgeConsole implements ForgeConsole,
PropertyChangeListener, DisposeListener {

private ForgeRuntime runtime;
private ForgeTextViewer textViewer;

public AbstractForgeConsole(ForgeRuntime runtime) {
this.runtime = runtime;
}

protected abstract ForgeTextViewer createTextViewer(Composite parent);

protected ForgeTextViewer getTextViewer() {
return textViewer;
}
Expand All @@ -30,12 +31,10 @@ public ForgeRuntime getRuntime() {
}

public String getLabel() {
return "Forge " +
getRuntime().getVersion() +
" - " +
getRuntime().getType().name().toLowerCase();
return "Forge " + getRuntime().getVersion() + " - "
+ getRuntime().getType().name().toLowerCase();
}

@Override
public Control createControl(Composite parent) {
if (textViewer == null) {
Expand All @@ -46,12 +45,17 @@ public Control createControl(Composite parent) {
result.addDisposeListener(this);
return textViewer.getControl();
}

@Override
public void widgetDisposed(DisposeEvent event) {
if (event.getSource() == getTextViewer().getControl()) {
getRuntime().removePropertyChangeListener(this);
}
}


@Override
public Resource<?> getCurrentResource() {
throw new UnsupportedOperationException();
}

}
Expand Up @@ -4,6 +4,8 @@

import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.Composite;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.tools.aesh.core.console.Console;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.core.runtime.ForgeRuntimeState;
import org.jboss.tools.forge.ui.internal.actions.StartAction;
Expand All @@ -12,24 +14,24 @@
import org.jboss.tools.forge.ui.internal.viewer.ForgeTextViewer;

public class F2Console extends AbstractForgeConsole {


private F2TextViewer textViewer;

public F2Console(ForgeRuntime runtime) {
super(runtime);
}
@Override

@Override
public ForgeTextViewer createTextViewer(Composite parent) {
return new F2TextViewer(parent);
return textViewer = new F2TextViewer(parent);
}

@Override
public IAction[] createActions() {
return new IAction[] {
new StartAction(getRuntime()),
new StopAction(getRuntime())
};
return new IAction[] { new StartAction(getRuntime()),
new StopAction(getRuntime()) };
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (ForgeRuntimeState.RUNNING.equals(evt.getNewValue())) {
Expand All @@ -39,5 +41,16 @@ public void propertyChange(PropertyChangeEvent evt) {
getTextViewer().stopConsole();
}
}


@Override
public Resource<?> getCurrentResource() {
Resource<?> currentResource = null;
if (textViewer != null) {
Console console = textViewer.getConsole();
if (console != null) {
currentResource = (Resource<?>) console.getCurrentResource();
}
}
return currentResource;
}
}
Expand Up @@ -3,13 +3,18 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jboss.forge.addon.resource.Resource;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;

public interface ForgeConsole {

String getLabel();

Control createControl(Composite parent);

IAction[] createActions();

ForgeRuntime getRuntime();

Resource<?> getCurrentResource();
}
Expand Up @@ -59,7 +59,12 @@ public UIContextImpl(UIProvider provider, IStructuredSelection selection) {
result.add(Proxies.unwrap(convertedObj));
} else {
for (Object object : selectedElements) {
if (object instanceof IResource) {
if (object instanceof Resource) {
result.add((Resource<?>) object);
} else if (object instanceof File) {
File file = (File) object;
result.add(Proxies.unwrap(converter.convert(file)));
} else if (object instanceof IResource) {
IPath location = ((IResource) object).getLocation();
if (location != null) {
File file = location.toFile();
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.forge.addon.ui.command.UICommand;
Expand All @@ -45,6 +46,7 @@
import org.jboss.tools.forge.ui.internal.ext.quickaccess.QuickAccessProvider;
import org.jboss.tools.forge.ui.internal.ext.quickaccess.impl.ForgeQuickAccessElement;
import org.jboss.tools.forge.ui.internal.ext.quickaccess.impl.ForgeQuickAccessProvider;
import org.jboss.tools.forge.ui.internal.part.ForgeConsoleView;
import org.jboss.tools.forge.ui.notifications.NotificationType;

public class UICommandListDialog extends PopupDialog {
Expand All @@ -66,7 +68,7 @@ public UICommandListDialog(IWorkbenchWindow window) {
if (selection instanceof TreeSelection) {
currentSelection = (TreeSelection) selection;
} else {
IFile activeEditorFile = getActiveEditorInput(window);
Object activeEditorFile = getActiveEditorInput(window);
if (activeEditorFile != null) {
currentSelection = new StructuredSelection(activeEditorFile);
}
Expand All @@ -78,19 +80,25 @@ public UICommandListDialog(IWorkbenchWindow window) {
/**
* Retrieves the {@link IFile} represented by the active editor
*/
private static IFile getActiveEditorInput(IWorkbenchWindow window) {
private static Object getActiveEditorInput(IWorkbenchWindow window) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
IEditorInput editorInput = part.getEditorInput();
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
IEditorInput editorInput = editor.getEditorInput();
if (editorInput != null) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput
.getAdapter(FileEditorInput.class);
if (fileEditorInput != null) {
return fileEditorInput.getFile();
}
}
} else {
IWorkbenchPart part = page.getActivePart();
if (part instanceof ForgeConsoleView) {
return ((ForgeConsoleView) part).getConsole()
.getCurrentResource();
}
}
}
return null;
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.jboss.tools.aesh.core.console.Console;
import org.jboss.tools.forge.core.runtime.ForgeRuntime;
import org.jboss.tools.forge.ui.internal.document.ForgeDocument;

Expand Down Expand Up @@ -181,5 +182,9 @@ public void run() {
}
});
}


@Override
public Console getConsole() {
throw new UnsupportedOperationException("getConsole() is not supported on this class");
}
}
Expand Up @@ -8,17 +8,23 @@
import org.jboss.tools.forge.ui.internal.cli.AeshConsole;

public class F2TextViewer extends AbstractTextViewer implements ForgeTextViewer {

public F2TextViewer(Composite parent) {
private AeshConsole console;

public F2TextViewer(Composite parent) {
super(parent);
if (ForgeRuntimeState.RUNNING.equals(FurnaceRuntime.INSTANCE.getState())) {
if (ForgeRuntimeState.RUNNING
.equals(FurnaceRuntime.INSTANCE.getState())) {
startConsole();
}
}

protected Console createConsole() {
return new AeshConsole();
}

return console = new AeshConsole();
}

@Override
public Console getConsole() {
return console;
}

}

@@ -1,11 +1,13 @@
package org.jboss.tools.forge.ui.internal.viewer;

import org.eclipse.swt.widgets.Control;
import org.jboss.tools.aesh.core.console.Console;

public interface ForgeTextViewer {

Control getControl();
void startConsole();
void stopConsole();
Console getConsole();

}

0 comments on commit 2ddc51a

Please sign in to comment.