Author: koen.aers(a)jboss.com
Date: 2012-01-13 04:54:00 -0500 (Fri, 13 Jan 2012)
New Revision: 37818
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/LinkHandler.java
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java
Log:
JBIDE-10270: Link with Editor button works
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml 2012-01-13 09:35:47 UTC (rev
37817)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/plugin.xml 2012-01-13 09:54:00 UTC (rev
37818)
@@ -44,11 +44,11 @@
description="Stop the default Forge runtime"
id="org.jboss.tools.forge.ui.stop"
name="Stop Forge"/>
-<!-- <command
+ <command
categoryId="org.jboss.tools.forge.ui"
description="Link the currently selected item to the running Forge
runtime"
id="org.jboss.tools.forge.ui.link"
- name="Link To Selection"/> -->
+ name="Link To Selection"/>
<command
categoryId="org.eclipse.ui.category.window"
defaultHandler="org.jboss.tools.forge.ui.commands.ForgeCommandListHandler"
@@ -59,33 +59,6 @@
<extension
point="org.eclipse.ui.menus">
<menuContribution
- locationURI="menu:org.jboss.tools.forge.ui.view">
- <command
- commandId="org.jboss.tools.forge.ui.start"
- icon="icons/start.gif"
- label="Start Forge"
- mnemonic="A"
- style="push"
- tooltip="Start the default Forge runtime">
- </command>
- <command
- commandId="org.jboss.tools.forge.ui.stop"
- icon="icons/stop.gif"
- label="Stop Forge"
- mnemonic="O"
- style="push"
- tooltip="Stop the running Forge runtime">
- </command>
-<!-- <command
- commandId="org.jboss.tools.forge.ui.link"
- icon="icons/link.gif"
- label="Link To Forge"
- mnemonic="L"
- style="toggle"
- tooltip="Link the current selection to Forge">
- </command> -->
- </menuContribution>
- <menuContribution
locationURI="toolbar:org.jboss.tools.forge.ui.view">
<command
commandId="org.jboss.tools.forge.ui.start"
@@ -103,14 +76,14 @@
style="push"
tooltip="Stop the running Forge runtime">
</command>
-<!-- <command
+ <command
commandId="org.jboss.tools.forge.ui.link"
icon="icons/link.gif"
label="Link To Forge"
mnemonic="L"
style="toggle"
tooltip="Link the current selection to Forge">
- </command> -->
+ </command>
</menuContribution>
</extension>
<extension
@@ -125,17 +98,17 @@
<perspectiveExtension
targetID = "org.eclipse.jst.j2ee.J2EEPerspective">
<showInPart
- id = "org.jboss.tools.forge.console"/>
+ id = "org.jboss.tools.forge.ui.view"/>
</perspectiveExtension>
<perspectiveExtension
targetID = "org.eclipse.jdt.ui.JavaPerspective">
<showInPart
- id = "org.jboss.tools.forge.console"/>
+ id = "org.jboss.tools.forge.ui.view"/>
</perspectiveExtension>
<perspectiveExtension
targetID = "org.jboss.tools.common.ui.JBossPerspective">
<showInPart
- id = "org.jboss.tools.forge.console"/>
+ id = "org.jboss.tools.forge.ui.view"/>
</perspectiveExtension>
</extension>
<extension
@@ -164,7 +137,7 @@
</with>
</enabledWhen>
</handler>
-<!-- <handler
+ <handler
class="org.jboss.tools.forge.ui.commands.LinkHandler"
commandId="org.jboss.tools.forge.ui.link">
<enabledWhen>
@@ -175,7 +148,7 @@
</equals>
</with>
</enabledWhen>
- </handler> -->
+ </handler>
</extension>
<extension
point="org.eclipse.ui.services">
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/LinkHandler.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/LinkHandler.java 2012-01-13
09:35:47 UTC (rev 37817)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/commands/LinkHandler.java 2012-01-13
09:54:00 UTC (rev 37818)
@@ -2,11 +2,27 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Widget;
+import org.jboss.tools.forge.ui.part.ForgeView;
+import org.jboss.tools.forge.ui.util.ForgeHelper;
public class LinkHandler extends AbstractHandler {
public Object execute(ExecutionEvent executionEvent) {
- System.out.println("Execute Link Handler");
+ Object object = executionEvent.getTrigger();
+ if (object != null && object instanceof Event) {
+ Widget widget = ((Event)object).widget;
+ if (widget != null) {
+ if (widget instanceof ToolItem) {
+ ForgeView forgeView = ForgeHelper.getForgeView();
+ if (forgeView != null) {
+ forgeView.setSynchronized(((ToolItem)widget).getSelection());
+ }
+ }
+ }
+ }
return null;
}
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-13
09:35:47 UTC (rev 37817)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/ForgeView.java 2012-01-13
09:54:00 UTC (rev 37818)
@@ -17,8 +17,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.IShowInTarget;
import org.eclipse.ui.part.MessagePage;
import org.eclipse.ui.part.Page;
@@ -74,23 +72,29 @@
private String notRunningMessage;
private ForgeRuntime runtime;
- private ISelection selection;
+// private ISelection selection;
+ private SelectionSynchronizer synchronizer;
@Override
public void createPartControl(Composite parent) {
+ synchronizer = new SelectionSynchronizer(this);
pageBook = new PageBook(parent, SWT.NONE);
createNotRunningPage(parent);
- showPage(notRunning);
- getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new
ISelectionListener() {
- @Override
- public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
- selection = newSelection;
- }
- });
+ showPage(notRunning);
+// getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new
ISelectionListener() {
+// @Override
+// public void selectionChanged(IWorkbenchPart part, ISelection newSelection) {
+// selection = newSelection;
+// }
+// });
}
- public ISelection getSelection() {
- return selection;
+// public ISelection getSelection() {
+// return selection;
+// }
+
+ public void setSynchronized(boolean synced) {
+ synchronizer.setEnabled(synced);
}
private void createNotRunningPage(Composite parent) {
Added:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
(rev 0)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java 2012-01-13
09:54:00 UTC (rev 37818)
@@ -0,0 +1,107 @@
+package org.jboss.tools.forge.ui.part;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPartService;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.jboss.tools.forge.core.process.ForgeRuntime;
+
+
+public class SelectionSynchronizer implements ISelectionListener {
+
+ private ForgeView forgeView;
+ private ISelectionService selectionService;
+ private IEditorPart selectedPart;
+ private IPartService partService;
+
+ private IPartListener partListener = new IPartListener() {
+
+ @Override
+ public void partOpened(IWorkbenchPart part) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void partDeactivated(IWorkbenchPart part) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+ if (!(part instanceof IEditorPart) || part == selectedPart) return;
+ selectedPart = (IEditorPart)part;
+ IEditorInput editorInput = selectedPart.getEditorInput();
+ if (!(editorInput instanceof IFileEditorInput)) return;
+ IFile file = ((IFileEditorInput)editorInput).getFile();
+ if (file == null) return;
+ String path = file.getLocation().toOSString();
+ if (path.indexOf(' ') != -1) {
+ path = '\"' + path + '\"';
+ }
+ ForgeRuntime forgeRuntime = forgeView.getRuntime();
+ if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
+ forgeRuntime.sendInput("pick-up " + path + "\n");
+ }
+ }
+
+ @Override
+ public void partActivated(IWorkbenchPart part) {
+ // TODO Auto-generated method stub
+
+ }
+ };
+
+ public SelectionSynchronizer(ForgeView forgeView) {
+ this.forgeView = forgeView;
+ IWorkbenchWindow workbenchWindow = forgeView.getSite().getWorkbenchWindow();
+ selectionService =
+ forgeView.getSite().getWorkbenchWindow().getSelectionService();
+ partService = workbenchWindow.getPartService();
+ }
+
+ public void setEnabled(boolean enabled) {
+ if (enabled) {
+// selectionService.addSelectionListener(this);
+ partService.addPartListener(partListener);
+ } else {
+// selectionService.removeSelectionListener(this);
+ partService.removePartListener(partListener);
+ }
+ }
+
+ @Override
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (!(part instanceof IEditorPart) || part == selectedPart) return;
+ selectedPart = (IEditorPart)part;
+ IWorkbenchWindow workbenchWindow = forgeView.getSite().getWorkbenchWindow();
+ if (workbenchWindow.getPartService().getActivePart() == part) return;
+ IEditorInput editorInput = selectedPart.getEditorInput();
+ if (!(editorInput instanceof IFileEditorInput)) return;
+ IFile file = ((IFileEditorInput)editorInput).getFile();
+ if (file == null) return;
+ String path = file.getLocation().toOSString();
+ if (path.indexOf(' ') != -1) {
+ path = '\"' + path + '\"';
+ }
+ ForgeRuntime forgeRuntime = forgeView.getRuntime();
+ if (forgeRuntime != null &&
ForgeRuntime.STATE_RUNNING.equals(forgeRuntime.getState())) {
+ forgeRuntime.sendInput("pick-up " + path + "\n");
+ }
+ }
+
+}
Property changes on:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/part/SelectionSynchronizer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Show replies by date