Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 201150 | Differences between
and this patch

Collapse All | Expand All

(-)src-recorder/org/eclipse/hyades/internal/execution/recorder/ui/views/RecorderControlView.java (-7 / +112 lines)
Lines 21-30 Link Here
21
import org.eclipse.hyades.test.core.internal.resources.TestCorePluginResourceBundle;
21
import org.eclipse.hyades.test.core.internal.resources.TestCorePluginResourceBundle;
22
import org.eclipse.hyades.test.core.testgen.ITestgenListener;
22
import org.eclipse.hyades.test.core.testgen.ITestgenListener;
23
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
23
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
24
import org.eclipse.jface.action.Action;
24
import org.eclipse.jface.action.GroupMarker;
25
import org.eclipse.jface.action.GroupMarker;
25
import org.eclipse.jface.action.ToolBarManager;
26
import org.eclipse.jface.action.ToolBarManager;
26
import org.eclipse.jface.dialogs.ErrorDialog;
27
import org.eclipse.jface.dialogs.ErrorDialog;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.dnd.Clipboard;
30
import org.eclipse.swt.dnd.TextTransfer;
31
import org.eclipse.swt.dnd.Transfer;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionListener;
28
import org.eclipse.swt.graphics.FontMetrics;
34
import org.eclipse.swt.graphics.FontMetrics;
29
import org.eclipse.swt.graphics.GC;
35
import org.eclipse.swt.graphics.GC;
30
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridData;
Lines 34-45 Link Here
34
import org.eclipse.swt.widgets.Canvas;
40
import org.eclipse.swt.widgets.Canvas;
35
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Display;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.Event;
37
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.List;
45
import org.eclipse.swt.widgets.List;
46
import org.eclipse.swt.widgets.Listener;
47
import org.eclipse.swt.widgets.Menu;
48
import org.eclipse.swt.widgets.MenuItem;
39
import org.eclipse.swt.widgets.Text;
49
import org.eclipse.swt.widgets.Text;
40
import org.eclipse.ui.IWorkbenchPage;
50
import org.eclipse.ui.IWorkbenchPage;
41
import org.eclipse.ui.IWorkbenchWindow;
51
import org.eclipse.ui.IWorkbenchWindow;
42
import org.eclipse.ui.PlatformUI;
52
import org.eclipse.ui.PlatformUI;
53
import org.eclipse.ui.actions.ActionFactory;
43
import org.eclipse.ui.part.ViewPart;
54
import org.eclipse.ui.part.ViewPart;
44
55
45
/**
56
/**
Lines 68-73 Link Here
68
	 */
79
	 */
69
	public static RecorderControlView instance=null;
80
	public static RecorderControlView instance=null;
70
	
81
	
82
	/**
83
	 * Setup the clipboard   
84
	 */
85
	private Clipboard clipboard;
86
	
87
	/**
88
	 * Create the action for copying
89
	 */
90
	private CopyAction copyAction;
91
	
71
		
92
		
72
	/**
93
	/**
73
	 * the view's ID
94
	 * the view's ID
Lines 81-87 Link Here
81
	/**
102
	/**
82
	 * @see ViewPart#createPartControl
103
	 * @see ViewPart#createPartControl
83
	 */
104
	 */
84
	public void createPartControl(Composite grandParent)  
105
	public void createPartControl(final Composite grandParent)  
85
	{		
106
	{		
86
		FontMetrics fm = new GC(grandParent).getFontMetrics();
107
		FontMetrics fm = new GC(grandParent).getFontMetrics();
87
		int heightHint = fm.getHeight() + fm.getAscent() + fm.getDescent();
108
		int heightHint = fm.getHeight() + fm.getAscent() + fm.getDescent();
Lines 120-134 Link Here
120
		recStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
141
		recStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
121
		
142
		
122
		
143
		
123
		statusList = new List(parent,SWT.V_SCROLL|SWT.H_SCROLL|SWT.READ_ONLY|SWT.BORDER);
144
		statusList = new List(parent,SWT.V_SCROLL|SWT.H_SCROLL|SWT.READ_ONLY|SWT.BORDER|SWT.MULTI);
124
		statusList.setLayoutData(new GridData(GridData.FILL_BOTH));
145
		statusList.setLayoutData(new GridData(GridData.FILL_BOTH));
125
	 		
146
		
126
		ToolBarManager toolbarManager = (ToolBarManager)getViewSite().getActionBars().getToolBarManager();
147
		clipboard = new Clipboard(grandParent.getDisplay());
148
		copyAction = new CopyAction( clipboard );
149
		copyAction.setEnabled( false );
150
		statusList.addSelectionListener( new SelectionListener() {
151
			public void widgetSelected(SelectionEvent e) {
152
				/* A new selection has been made in the Recorder Control ...
153
				 * Update the selected lines */
154
				setSelectedLines();
155
			}
156
			public void widgetDefaultSelected(SelectionEvent e) {}
157
		});
158
159
		/* Add the support for the context menu */
160
		statusList.addListener( SWT.MenuDetect, new Listener () {
161
			public void handleEvent (Event event) {
162
				Menu menu = new Menu( grandParent.getShell(), SWT.POP_UP );
127
				
163
				
164
				MenuItem copyItem = new MenuItem( menu, SWT.PUSH );
165
				copyItem.setText( UiPluginResourceBundle.command_Copy );
166
				copyItem.addListener( SWT.Selection, new Listener () {
167
					public void handleEvent (Event e) {
168
						setSelectedLines();
169
						copyAction.run();
170
					}
171
				});
172
				menu.setLocation( event.x, event.y );
173
				MenuItem selectAllItem = new MenuItem( menu, SWT.PUSH );
174
				selectAllItem.setText( UiPluginResourceBundle.command_SelectAll );
175
				selectAllItem.addListener( SWT.Selection, new Listener() {
176
					public void handleEvent (Event e) {
177
						statusList.selectAll();
178
						setSelectedLines();
179
						copyAction.setEnabled( true );
180
					}
181
				});
182
				if ( statusList.getSelection().length == 0 ) {
183
					copyAction.setEnabled( false );
184
					copyItem.setEnabled( false );
185
				}
186
				menu.setVisible( true );
187
			}
188
		});
189
		
190
		getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction);
191
		ToolBarManager toolbarManager = (ToolBarManager)getViewSite().getActionBars().getToolBarManager();
192
		
128
		//add new items group
193
		//add new items group
129
		toolbarManager.add(new GroupMarker(STARTGROUP));
194
		toolbarManager.add(new GroupMarker(STARTGROUP));
130
		toolbarManager.add(new StopRecordingAction());		
195
		toolbarManager.add(new StopRecordingAction());							
131
					
196
	}
197
	
198
	private void setSelectedLines() {
199
		if ( statusList != null && copyAction != null ) {
200
			String[] statusLines = statusList.getSelection();
201
			copyAction.setSelectedStatusItems( statusLines );
202
			copyAction.setEnabled( statusLines.length == 0 ? false : true );
203
		}
132
	}
204
	}
133
205
134
	/**
206
	/**
Lines 257-263 Link Here
257
	 */
329
	 */
258
	public void setFocus()
330
	public void setFocus()
259
	{
331
	{
260
332
		setSelectedLines();
333
		copyAction.setEnabled( statusList.getSelection().length == 0 ? false : true );
261
	}
334
	}
262
335
263
	/**
336
	/**
Lines 323-326 Link Here
323
        }
396
        }
324
        
397
        
325
    }
398
    }
399
        
400
    class CopyAction extends Action { 
401
    	private Clipboard clipboard;
402
    	private String[] selectedItems;
403
    	
404
    	public CopyAction( Clipboard clipboardVal ) {
405
    		super();
406
    		if ( clipboardVal == null ) {
407
    			throw new IllegalArgumentException("Unable to perform copy action due to 'clipboard == null'"); //$NON-NLS-1$
408
    		}
409
    		clipboard = clipboardVal;
410
    	}
411
    	
412
    	public void setSelectedStatusItems( String[] selectedItems ) {
413
    		this.selectedItems = selectedItems; 
414
    	}
415
416
    	public void run() {
417
    		/* Return if there are no selected items */
418
    		if ( this.selectedItems.length == 0 ) return;
419
    		
420
    		/* Copy the items to the clipboard */
421
    		StringBuffer status = new StringBuffer();
422
    		for ( int i = 0; i < selectedItems.length; i++ ) 
423
    			status.append( selectedItems[i] + "\n" );
424
    	
425
    		clipboard.setContents( new String[] { status.toString() }, 
426
    			new Transfer[] { TextTransfer.getInstance() });
427
    		
428
    	}
429
    	
430
    }
326
}
431
}

Return to bug 201150