www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - dwt2: IllegalArgumentException at

reply yidabu <dyuyan.spam gmail.com> writes:
dwt 2 updated to revision 70, the app still not work
1. right click on tree node A, popup a contextmenu
2. right click on tree node B, popup a contextmenu
3. right click on tree node A, the contenextmenu is not shown

the issue maybe releated to ActionContributionItem.updateImages
the exception from sample code:

Unhandled D Exception (tango.core.Exception.IllegalArgumentException
 "Argument not valid") at KERNEL32.dll (0x7c812a5b) thread(4092)
->us





org\eclipse\swt\widgets\Widget.d:492

org\eclipse\swt\widgets\Item.d:168

org\eclipse\swt\widgets\MenuItem.d:788

onItem.updateImages () at org\eclipse\jface\action\ActionContributionItem.d:1131

ributionItem.update () at org\eclipse\jface\action\ActionContributionItem.d:959

ntributionItem.fill () at org\eclipse\jface\action\ActionContributionItem.d:306

() at org\eclipse\jface\action\MenuManager.d:752

at org\eclipse\jface\action\MenuManager.d:833

r.handleAboutToShow () at org\eclipse\jface\action\MenuManager.d:485

ager.initializeMenu () at org\eclipse\jface\action\MenuManager.d:506

istener.handleEvent () at org\eclipse\swt\widgets\TypedListener.d:279

at org\eclipse\swt\widgets\EventTable.d:91

org\eclipse\swt\widgets\Widget.d:1037

org\eclipse\swt\widgets\Widget.d:1059

org\eclipse\swt\widgets\Widget.d:1041

org.eclipse.swt.widgets.Control.Control.WM_INITMENUPOPUP () at
org\eclipse\swt\widgets\Control.d:4163

org\eclipse\swt\widgets\Control.d:3865

org\eclipse\swt\widgets\Canvas.d:357

() at org\eclipse\swt\widgets\Decorations.d:1610

org\eclipse\swt\widgets\Shell.d:1997

org\eclipse\swt\widgets\Display.d:4646

hwnd = 0x00110562) at org\eclipse\swt\widgets\Display.d:4596






org\eclipse\swt\widgets\Menu.d:266

org\eclipse\swt\widgets\Display.d:3951

at org\eclipse\swt\widgets\Display.d:3516


runMain(void*) () from dmain2

runAll(void*) () from dmain2



->q




the sample code:


/*******************************************************************************
 * Copyright (c) 2006 Tom Schindl and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tom Schindl - initial API and implementation
 * Port to the D programming language:
 *     wbaxter at gmail dot com
 *******************************************************************************/

module org.eclipse.jface.snippets.viewers.Snippet002TreeViewer;

import org.eclipse.swt.SWT;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import java.lang.all;

import tango.util.Convert;
import tango.io.Stdout;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
    

/**
 * A simple TreeViewer to demonstrate usage
 *
 *  author Tom Schindl <tom.schindl bestsolution.at>
 *
 */
class Snippet002TreeViewer {
	private class MyContentProvider : ITreeContentProvider {

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
		 */
		public Object[] getElements(Object inputElement) {
			return (cast(MyModel)inputElement).child/*.dup*/;
		}

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.IContentProvider#dispose()
		 */
		public void dispose() {

		}

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.j
ace.viewers.Viewer, java.lang.Object, java.lang.Object)
		 */
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

		}

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
		 */
		public Object[] getChildren(Object parentElement) {
			return getElements(parentElement);
		}

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
		 */
		public Object getParent(Object element) {
			if( element is null) {
				return null;
			}

			return (cast(MyModel)element).parent;
		}

		/* (non-Javadoc)
		 *  see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
		 */
		public bool hasChildren(Object element) {
			return (cast(MyModel)element).child.length > 0;
		}

	}

	public class MyModel {
		public MyModel parent;
		public MyModel[] child;
		public int counter;

		public this(int counter, MyModel parent) {
			this.parent = parent;
			this.counter = counter;
		}

		public String toString() {
			String rv = "Item ";
			if( parent !is null ) {
				rv = parent.toString() ~ ".";
			}

			rv ~= to!(char[])(counter);

			return rv;
		}
	}

    public class Test2Action : Action
    {
        public this() { 
            super("&Test2 Action Ctrl+X",
ImageDescriptor.createFromFile(getImportData!("eclipse-red-16.png"))); // not
work
            //super("&Test2 Action Ctrl+X", null); works 
        }                      
        public void run() { }
    }      
    
    public class TestAction : Action
    {
        public this() { 
            super("&Test Action Ctrl+X",
ImageDescriptor.createFromFile(getImportData!("eclipse-red-16.png"))); // not
work
            //super("&Test Action Ctrl+X", null); //works
        }                      
        public void run() { }
    }   
    
    class MyListener : IMenuListener
    {

        void menuAboutToShow(IMenuManager manager)
        {
            //auto t = Kiss.instance.natural(0,2);
            static int t = 0;
            if( t == 0)
            {
                manager.add(new TestAction);
                t = 1;
                
            }
            else
            {
                manager.add(new TestAction);
                t = 0;
            }
	    /*
		in my app:
		if(nodea)
		{
			manager.add(actiona);
			manager.add(actionb);
		}
		else if(nodeb)
		{
			manager.add(actionc);
			manager.add(actiond);
		}
			manager.add(actione);

	  */
        }

    }
    //
        
    TestAction testAction;
    Test2Action test2Action;

	public this(Shell shell) {
        
        testAction = new TestAction();
        test2Action = new Test2Action();
        
		TreeViewer v = new TreeViewer(shell);
		v.setLabelProvider(new LabelProvider());
		v.setContentProvider(new MyContentProvider());
		v.setInput(createModel());        
        auto menuManager = new MenuManager();
        menuManager.setRemoveAllWhenShown(true);
        menuManager.addMenuListener( new MyListener());
    
        auto menu = menuManager.createContextMenu( v.getControl() );
        v.getControl.setMenu( menu );      
        

	}

	private MyModel createModel() {
		MyModel root = new MyModel(0,null);
		root.counter = 0;

		MyModel tmp;
		for( int i = 1; i < 10; i++ ) {
			tmp = new MyModel(i, root);
			root.child ~= tmp;
			for( int j = 1; j < i; j++ ) {
				tmp.child ~= new MyModel(j,tmp);
			}
		}

		return root;
	}

}


void main() {
    Display display = new Display ();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new Snippet002TreeViewer(shell);
    shell.open ();

    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }

    display.dispose ();
}
 








-- 
yidabu <yidabu.spam gmail.com>
http://www.dsource.org/projects/dwin/

D ÓïÑÔ-ÖÐÎÄ(D Chinese):
http://www.d-programming-language-china.org/
http://bbs.d-programming-language-china.org/
http://dwin.d-programming-language-china.org/
http://scite4d.d-programming-language-china.org/
Apr 08 2009
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
yidabu schrieb:
 dwt 2 updated to revision 70, the app still not work
 1. right click on tree node A, popup a contextmenu
 2. right click on tree node B, popup a contextmenu
 3. right click on tree node A, the contenextmenu is not shown
 
 the issue maybe releated to ActionContributionItem.updateImages
 the exception from sample code:
 
It is fixed now. Was an error in the impl of java.util.HashMap remove()
Apr 11 2009
parent yidabu <dyuyan.spam gmail.com> writes:
On Sat, 11 Apr 2009 11:34:39 +0200
Frank Benoit <keinfarbton googlemail.com> wrote:

 yidabu schrieb:
 dwt 2 updated to revision 70, the app still not work
 1. right click on tree node A, popup a contextmenu
 2. right click on tree node B, popup a contextmenu
 3. right click on tree node A, the contenextmenu is not shown
 
 the issue maybe releated to ActionContributionItem.updateImages
 the exception from sample code:
 
It is fixed now. Was an error in the impl of java.util.HashMap remove()
Thanks, now works fine. -- yidabu <yidabu.spam gmail.com> http://www.dsource.org/projects/dwin/ D ÓïÑÔ-ÖÐÎÄ(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/
Apr 11 2009