Permalink
Browse files

test run history

  • Loading branch information...
1 parent 5993992 commit 33d8d7d009b1269663326bc9656ac8b13e84a122 @JPMoresmau committed Nov 15, 2012
@@ -103,6 +103,14 @@ public int getFailures() {
return failures;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getName();
+ }
+
@Override
public int hashCode() {
final int prime = 31;
@@ -43,4 +43,4 @@ toggle_breakpoint=Toggle Breakpoint
haskellInteractiveLaunchType_name = Haskell interactive session
-test_result_view=Haskell test results
+test_result_view=Haskell Test Results
@@ -64,6 +64,9 @@
public static String test_view_errors;
public static String test_view_failures;
public static String test_view_text;
+ public static String test_history;
+ public static String test_history_clear;
+ public static String test_history_none;
private static final String BUNDLE_NAME
= UITexts.class.getPackage().getName() + ".uitexts"; //$NON-NLS-1$
@@ -55,3 +55,6 @@ test_view_runs=Runs
test_view_errors=Errors
test_view_failures=Failures
test_view_text=Test output
+test_history=Test run History...
+test_history_clear=Clear terminated
+test_history_none=No history
@@ -6,6 +6,7 @@
package net.sf.eclipsefp.haskell.debug.ui.test;
import net.sf.eclipsefp.haskell.debug.core.test.TestResult;
+import net.sf.eclipsefp.haskell.debug.core.test.TestSuite;
import net.sf.eclipsefp.haskell.ui.util.HaskellUIImages;
import net.sf.eclipsefp.haskell.ui.util.IImageNames;
import org.eclipse.jface.viewers.LabelProvider;
@@ -44,6 +45,8 @@ public Image getImage( final Object element ) {
if (key!=null){
return HaskellUIImages.getImage( key );
}
+ } else if (element instanceof TestSuite){
+ return getImage(( (TestSuite )element).getRoot());
}
return super.getImage( element );
}
@@ -5,14 +5,21 @@
*/
package net.sf.eclipsefp.haskell.debug.ui.test;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.debug.core.test.TestResult;
+import net.sf.eclipsefp.haskell.debug.core.test.TestStatus;
import net.sf.eclipsefp.haskell.debug.core.test.TestSuite;
import net.sf.eclipsefp.haskell.debug.ui.internal.util.UITexts;
import net.sf.eclipsefp.haskell.ui.handlers.OpenDefinitionHandler;
import net.sf.eclipsefp.haskell.ui.util.HaskellUIImages;
import net.sf.eclipsefp.haskell.ui.util.IImageNames;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuCreator;
+import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -22,6 +29,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
@@ -32,6 +41,8 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
@@ -50,6 +61,9 @@
private Text tErrors;
private Text tFailures;
+ private final List<TestSuite> history=new ArrayList<TestSuite>();
+ private int historyIndex=-1;
+
// private final List<Resource> resources=new ArrayList<Resource>();
/* (non-Javadoc)
@@ -175,16 +189,38 @@ public void handleEvent( final Event event ) {
}
});
+
+ IToolBarManager tmgr=getViewSite().getActionBars().getToolBarManager();
+ HistoryAction act=new HistoryAction();
+
+ tmgr.add( act );
+ }
+
+ public void clear(){
+ testTree.setInput( Collections.emptySet() );
+ tRuns.setText( String.valueOf( 0 ) );
+ tErrors.setText( String.valueOf( 0 ) );
+ tFailures.setText( String.valueOf( 0 ) );
+ tRuns.getParent().layout( new Control[]{tRuns,tErrors,tFailures} );
}
- public void setInput(final TestSuite ts){
+ /**
+ * set the given test suite as input
+ * @param ts the test suite
+ * @param add add to history?
+ */
+ public void setInput(final TestSuite ts,final boolean add){
testTree.setInput( Collections.singleton( ts.getRoot() ));
testTree.expandToLevel( 2 );
tRuns.setText( String.valueOf( ts.getRuns() ) );
tErrors.setText( String.valueOf( ts.getErrors() ) );
tFailures.setText( String.valueOf( ts.getFailures() ) );
tRuns.getParent().layout( new Control[]{tRuns,tErrors,tFailures} );
+ if (add){
+ history.add( ts );
+ historyIndex=history.size()-1;
+ }
}
/* (non-Javadoc)
@@ -198,4 +234,119 @@ public void setFocus() {
}
+ /**
+ * dynamic history menu
+ * @author JP Moresmau
+ *
+ */
+ private class HistoryMenuCreator implements IMenuCreator{
+ private Menu menu;
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
+ */
+ @Override
+ public Menu getMenu( final Control paramControl ) {
+ dispose();
+ menu=new Menu(paramControl);
+ fillMenu(menu);
+ return menu;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
+ */
+ @Override
+ public Menu getMenu( final Menu paramMenu ) {
+ dispose();
+ menu=new Menu(paramMenu);
+ fillMenu(menu);
+ return menu;
+ }
+
+ private void fillMenu(final Menu m){
+ if(history.size()>0){
+ TestResultLP lp=new TestResultLP();
+ for (int a=history.size()-1;a>=0;a--){
+ final TestSuite ts=history.get( a );
+ MenuItem mi=new MenuItem(m,SWT.RADIO);
+ mi.setText( lp.getText( ts ) );
+ mi.setImage( lp.getImage( ts ) );
+ if (historyIndex!=a){
+ final int idx=a;
+
+ mi.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ historyIndex=idx;
+ setInput( ts,false );
+ }
+ } );
+ } else {
+ mi.setSelection( true );
+ }
+ }
+ new MenuItem(m,SWT.SEPARATOR);
+ /** clear all terminated **/
+ MenuItem mi=new MenuItem(m,SWT.PUSH);
+ mi.setText( UITexts.test_history_clear);
+ mi.setImage( HaskellUIImages.getImage( IImageNames.REMOVE_ALL ) );
+ mi.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ int a=0;
+ for (Iterator<TestSuite> it=history.iterator();it.hasNext();){
+ final TestSuite ts=it.next();
+ /** terminated= !PENDING **/
+ if (!ts.getRoot().getStatus().equals( TestStatus.PENDING )){
+ it.remove();
+ /** history index moves too **/
+ if (historyIndex>=a){
+ historyIndex--;
+ }
+ }
+ }
+ /** defensive **/
+ if (historyIndex<0){
+ historyIndex=history.size()-1;
+ }
+ if (historyIndex>=0){
+ setInput( history.get( historyIndex ), false );
+ } else {
+ clear(); /** remove **/
+ }
+ }
+ } );
+ } else {
+ /** nothing to show **/
+ MenuItem mi=new MenuItem(m,SWT.PUSH);
+ mi.setText( UITexts.test_history_none);
+ mi.setEnabled( false );
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.IMenuCreator#dispose()
+ */
+ @Override
+ public void dispose() {
+ if (menu!=null){
+ menu.dispose();
+ }
+
+ }
+ }
+
+ /**
+ * simple action for test run history, delegates to menu creator
+ * @author JP Moresmau
+ *
+ */
+ private class HistoryAction extends Action {
+ private HistoryAction(){
+ super(UITexts.test_history, SWT.DROP_DOWN);
+ this.setImageDescriptor( HaskellUIImages.getImageDescriptor( IImageNames.HISTORY_LIST ) );
+ setMenuCreator( new HistoryMenuCreator() );
+ }
+ }
}
@@ -46,7 +46,7 @@ public void start( final TestSuite ts ) {
public void run() {
TestResultView view=getView();
if (view!=null){
- view.setInput( ts );
+ view.setInput( ts,true );
}
}
} );
@@ -64,7 +64,7 @@ public void update( final TestSuite ts ) {
public void run() {
TestResultView view=getView();
if (view!=null){
- view.setInput( ts );
+ view.setInput( ts,false );
}
}
} );
@@ -81,7 +81,7 @@ public void end( final TestSuite ts ) {
public void run() {
TestResultView view=getView();
if (view!=null){
- view.setInput( ts );
+ view.setInput( ts,false );
}
}
} );
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -128,6 +128,8 @@ private static void declareImages() {
declare(TEST_FAIL,OBJECT+"testfail.gif");
declare(TEST_OK,OBJECT+"testok.gif");
declare(TEST_RUN,OBJECT+"testrun.gif");
+ declare(HISTORY_LIST,ACTION_E+"history_list.gif");
+ declare(REMOVE_ALL,ACTION_E+"removeall.gif");
}
private final static void declare( final String key,
@@ -104,4 +104,6 @@
String TEST_FAIL = ID+".TEST_FAIL"; //$NON-NLS-1$
String TEST_OK = ID+".TEST_OK"; //$NON-NLS-1$
String TEST_RUN = ID+".TEST_RUN"; //$NON-NLS-1$
+ String HISTORY_LIST = ID+".HISTORY_LIST"; //$NON-NLS-1$
+ String REMOVE_ALL= ID+".REMOVE_ALL"; //$NON-NLS-1$
}

0 comments on commit 33d8d7d

Please sign in to comment.