Quantcast

Adding a palette to MultiView

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding a palette to MultiView

Scott Kaylie-2
How do I add a palette to the Design view of a multiview editor?  The
Palette API tutorial is very helpful for adding a palette to a new
TopComponent by creating a new lookup and putting a PaletteController
instance in it's InstanceContent, but I am not subclassing TopComponent
and don't know 1) what TopComponent to add the PaletteController to or
2) how to add the PaletteController to any lookup (i.e. there's no
lookup.add(Object x) ).

Btw, why isn't there an add(Object x) method for a Lookup?  It seems
that could make things a lot easier in a bunch of places.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

David Havrda
Scott Kaylie wrote:

> How do I add a palette to the Design view of a multiview editor?  The
> Palette API tutorial is very helpful for adding a palette to a new
> TopComponent by creating a new lookup and putting a PaletteController
> instance in it's InstanceContent, but I am not subclassing
> TopComponent and don't know 1) what TopComponent to add the
> PaletteController to or 2) how to add the PaletteController to any
> lookup (i.e. there's no lookup.add(Object x) ).
>
> Btw, why isn't there an add(Object x) method for a Lookup?  It seems
> that could make things a lot easier in a bunch of places.
>
Here is what I did.  In my class (extends TopComponent) constructor I
created a PaletteController.  Then in my getLookup method I did this

    public Lookup getLookup() {
       
        if(null == lookup){
            Lookup[] lookups = new
Lookup[]{dobj.getNodeDelegate().getLookup(),
            Lookups.fixed(new Object[]{paletteController, diagram})};
            lookup = new ProxyLookup(lookups);
        }
        return lookup;
    }

Seems to work ok for me.  Let me know if you have any problems.

-dave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

Scott Kaylie-2
Thanks David, but as I mention in my original post, I am not subclassing
TopComponent (the one being used is created by either my
DesignMultiViewDesc or ToolBarMVElement), so I do not have a
TopComponent.getLookup() method to override.  So, I need to know 1) what
TopComponent (or other object) to add the PaletteController to and 2)
how do I add to that component's lookup when I am not overriding it's
getLookup() method?




David Havrda wrote:

> Scott Kaylie wrote:
>
>> How do I add a palette to the Design view of a multiview editor?  The
>> Palette API tutorial is very helpful for adding a palette to a new
>> TopComponent by creating a new lookup and putting a PaletteController
>> instance in it's InstanceContent, but I am not subclassing
>> TopComponent and don't know 1) what TopComponent to add the
>> PaletteController to or 2) how to add the PaletteController to any
>> lookup (i.e. there's no lookup.add(Object x) ).
>>
>> Btw, why isn't there an add(Object x) method for a Lookup?  It seems
>> that could make things a lot easier in a bunch of places.
>>
> Here is what I did.  In my class (extends TopComponent) constructor I
> created a PaletteController.  Then in my getLookup method I did this
>
>    public Lookup getLookup() {
>              if(null == lookup){
>            Lookup[] lookups = new
> Lookup[]{dobj.getNodeDelegate().getLookup(),
>            Lookups.fixed(new Object[]{paletteController, diagram})};
>            lookup = new ProxyLookup(lookups);
>        }
>        return lookup;
>    }
>
> Seems to work ok for me.  Let me know if you have any problems.
>
> -dave
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

David Havrda
Sorry about that.

So in your DesignMultiViewDesc you return a MultiViewElement correct?  
What class type are you returning there?  I mean you have to be
returning a JComponent in the getVisualRepresentation correct?  In my
case my class is just a JPanel extending TopComponent.  What are you using?

-dave

Scott Kaylie wrote:

> Thanks David, but as I mention in my original post, I am not
> subclassing TopComponent (the one being used is created by either my
> DesignMultiViewDesc or ToolBarMVElement), so I do not have a
> TopComponent.getLookup() method to override.  So, I need to know 1)
> what TopComponent (or other object) to add the PaletteController to
> and 2) how do I add to that component's lookup when I am not
> overriding it's getLookup() method?
>
>
>
>
> David Havrda wrote:
>
>> Scott Kaylie wrote:
>>
>>> How do I add a palette to the Design view of a multiview editor?  
>>> The Palette API tutorial is very helpful for adding a palette to a
>>> new TopComponent by creating a new lookup and putting a
>>> PaletteController instance in it's InstanceContent, but I am not
>>> subclassing TopComponent and don't know 1) what TopComponent to add
>>> the PaletteController to or 2) how to add the PaletteController to
>>> any lookup (i.e. there's no lookup.add(Object x) ).
>>>
>>> Btw, why isn't there an add(Object x) method for a Lookup?  It seems
>>> that could make things a lot easier in a bunch of places.
>>>
>> Here is what I did.  In my class (extends TopComponent) constructor I
>> created a PaletteController.  Then in my getLookup method I did this
>>
>>    public Lookup getLookup() {
>>              if(null == lookup){
>>            Lookup[] lookups = new
>> Lookup[]{dobj.getNodeDelegate().getLookup(),
>>            Lookups.fixed(new Object[]{paletteController, diagram})};
>>            lookup = new ProxyLookup(lookups);
>>        }
>>        return lookup;
>>    }
>>
>> Seems to work ok for me.  Let me know if you have any problems.
>>
>> -dave
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

Scott Kaylie-2
All object representations are JPanels produced by my subclass of
InnerPanelFactory.  Can you add a PaletteController to a JPanel (if you
subclassed it and created a Lookup for it) and would the windowing
system know to look there and create the palette?



David Havrda wrote:

> Sorry about that.
>
> So in your DesignMultiViewDesc you return a MultiViewElement correct?  
> What class type are you returning there?  I mean you have to be
> returning a JComponent in the getVisualRepresentation correct?  In my
> case my class is just a JPanel extending TopComponent.  What are you
> using?
>
> -dave
>
> Scott Kaylie wrote:
>
>> Thanks David, but as I mention in my original post, I am not
>> subclassing TopComponent (the one being used is created by either my
>> DesignMultiViewDesc or ToolBarMVElement), so I do not have a
>> TopComponent.getLookup() method to override.  So, I need to know 1)
>> what TopComponent (or other object) to add the PaletteController to
>> and 2) how do I add to that component's lookup when I am not
>> overriding it's getLookup() method?
>>
>>
>>
>>
>> David Havrda wrote:
>>
>>> Scott Kaylie wrote:
>>>
>>>> How do I add a palette to the Design view of a multiview editor?  
>>>> The Palette API tutorial is very helpful for adding a palette to a
>>>> new TopComponent by creating a new lookup and putting a
>>>> PaletteController instance in it's InstanceContent, but I am not
>>>> subclassing TopComponent and don't know 1) what TopComponent to add
>>>> the PaletteController to or 2) how to add the PaletteController to
>>>> any lookup (i.e. there's no lookup.add(Object x) ).
>>>>
>>>> Btw, why isn't there an add(Object x) method for a Lookup?  It
>>>> seems that could make things a lot easier in a bunch of places.
>>>>
>>> Here is what I did.  In my class (extends TopComponent) constructor
>>> I created a PaletteController.  Then in my getLookup method I did this
>>>
>>>    public Lookup getLookup() {
>>>              if(null == lookup){
>>>            Lookup[] lookups = new
>>> Lookup[]{dobj.getNodeDelegate().getLookup(),
>>>            Lookups.fixed(new Object[]{paletteController, diagram})};
>>>            lookup = new ProxyLookup(lookups);
>>>        }
>>>        return lookup;
>>>    }
>>>
>>> Seems to work ok for me.  Let me know if you have any problems.
>>>
>>> -dave
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

David Havrda
Yes.  Just have your panel subclass TopComponent.  Everything works
fine.  That is though my JPanel is what is returned by the call to
MultiViewElement.getVisualRepresentation.

Scott Kaylie wrote:

> All object representations are JPanels produced by my subclass of
> InnerPanelFactory.  Can you add a PaletteController to a JPanel (if
> you subclassed it and created a Lookup for it) and would the windowing
> system know to look there and create the palette?
>
>
>
> David Havrda wrote:
>
>> Sorry about that.
>>
>> So in your DesignMultiViewDesc you return a MultiViewElement
>> correct?  What class type are you returning there?  I mean you have
>> to be returning a JComponent in the getVisualRepresentation correct?  
>> In my case my class is just a JPanel extending TopComponent.  What
>> are you using?
>>
>> -dave
>>
>> Scott Kaylie wrote:
>>
>>> Thanks David, but as I mention in my original post, I am not
>>> subclassing TopComponent (the one being used is created by either my
>>> DesignMultiViewDesc or ToolBarMVElement), so I do not have a
>>> TopComponent.getLookup() method to override.  So, I need to know 1)
>>> what TopComponent (or other object) to add the PaletteController to
>>> and 2) how do I add to that component's lookup when I am not
>>> overriding it's getLookup() method?
>>>
>>>
>>>
>>>
>>> David Havrda wrote:
>>>
>>>> Scott Kaylie wrote:
>>>>
>>>>> How do I add a palette to the Design view of a multiview editor?  
>>>>> The Palette API tutorial is very helpful for adding a palette to a
>>>>> new TopComponent by creating a new lookup and putting a
>>>>> PaletteController instance in it's InstanceContent, but I am not
>>>>> subclassing TopComponent and don't know 1) what TopComponent to
>>>>> add the PaletteController to or 2) how to add the
>>>>> PaletteController to any lookup (i.e. there's no lookup.add(Object
>>>>> x) ).
>>>>>
>>>>> Btw, why isn't there an add(Object x) method for a Lookup?  It
>>>>> seems that could make things a lot easier in a bunch of places.
>>>>>
>>>> Here is what I did.  In my class (extends TopComponent) constructor
>>>> I created a PaletteController.  Then in my getLookup method I did this
>>>>
>>>>    public Lookup getLookup() {
>>>>              if(null == lookup){
>>>>            Lookup[] lookups = new
>>>> Lookup[]{dobj.getNodeDelegate().getLookup(),
>>>>            Lookups.fixed(new Object[]{paletteController, diagram})};
>>>>            lookup = new ProxyLookup(lookups);
>>>>        }
>>>>        return lookup;
>>>>    }
>>>>
>>>> Seems to work ok for me.  Let me know if you have any problems.
>>>>
>>>> -dave
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

Scott Kaylie-2
My panels cannot subclass TopComponent.  They are subclasses of
SectionInnerPanel because that is what is required to be returned by the
InnerPanelFactory.

David Havrda wrote:

> Yes.  Just have your panel subclass TopComponent.  Everything works
> fine.  That is though my JPanel is what is returned by the call to
> MultiViewElement.getVisualRepresentation.
>
> Scott Kaylie wrote:
>
>> All object representations are JPanels produced by my subclass of
>> InnerPanelFactory.  Can you add a PaletteController to a JPanel (if
>> you subclassed it and created a Lookup for it) and would the
>> windowing system know to look there and create the palette?
>>
>>
>>
>> David Havrda wrote:
>>
>>> Sorry about that.
>>>
>>> So in your DesignMultiViewDesc you return a MultiViewElement
>>> correct?  What class type are you returning there?  I mean you have
>>> to be returning a JComponent in the getVisualRepresentation
>>> correct?  In my case my class is just a JPanel extending
>>> TopComponent.  What are you using?
>>>
>>> -dave
>>>
>>> Scott Kaylie wrote:
>>>
>>>> Thanks David, but as I mention in my original post, I am not
>>>> subclassing TopComponent (the one being used is created by either
>>>> my DesignMultiViewDesc or ToolBarMVElement), so I do not have a
>>>> TopComponent.getLookup() method to override.  So, I need to know 1)
>>>> what TopComponent (or other object) to add the PaletteController to
>>>> and 2) how do I add to that component's lookup when I am not
>>>> overriding it's getLookup() method?
>>>>
>>>>
>>>>
>>>>
>>>> David Havrda wrote:
>>>>
>>>>> Scott Kaylie wrote:
>>>>>
>>>>>> How do I add a palette to the Design view of a multiview editor?  
>>>>>> The Palette API tutorial is very helpful for adding a palette to
>>>>>> a new TopComponent by creating a new lookup and putting a
>>>>>> PaletteController instance in it's InstanceContent, but I am not
>>>>>> subclassing TopComponent and don't know 1) what TopComponent to
>>>>>> add the PaletteController to or 2) how to add the
>>>>>> PaletteController to any lookup (i.e. there's no
>>>>>> lookup.add(Object x) ).
>>>>>>
>>>>>> Btw, why isn't there an add(Object x) method for a Lookup?  It
>>>>>> seems that could make things a lot easier in a bunch of places.
>>>>>>
>>>>> Here is what I did.  In my class (extends TopComponent)
>>>>> constructor I created a PaletteController.  Then in my getLookup
>>>>> method I did this
>>>>>
>>>>>    public Lookup getLookup() {
>>>>>              if(null == lookup){
>>>>>            Lookup[] lookups = new
>>>>> Lookup[]{dobj.getNodeDelegate().getLookup(),
>>>>>            Lookups.fixed(new Object[]{paletteController, diagram})};
>>>>>            lookup = new ProxyLookup(lookups);
>>>>>        }
>>>>>        return lookup;
>>>>>    }
>>>>>
>>>>> Seems to work ok for me.  Let me know if you have any problems.
>>>>>
>>>>> -dave
>>>>>
>>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding a palette to MultiView

Scott Kaylie-2
After trying a few different places, I found one that works for showing
the palette.  If you are subclassing ToolBarMultiViewElement, you need
to add a PaletteController to it's lookup.  You set up a new Lookup for
your subclass (temp below), combine it with the superclass's Lookup via
a ProxyLookup, and then override getLookup() to return the ProxyLookup.

public class NewToolBarMVElement extends ToolBarMultiViewElement {
    private Lookup proxyLookup;
    private InstanceContent content = new InstanceContent();
   
    /** Creates a new instance of DesignMultiViewElement */
    public NewToolBarMVElement(XmlMultiViewDataObject dObj) {
        super(dObj);

        ...
     
        Lookup temp = new AbstractLookup(this.content);
        this.proxyLookup = new ProxyLookup(new Lookup[]{temp,
super.getLookup()});
        final PaletteController controller=
NewPaletteUtilities.createPalette();  //static method from custom class
        this.content.add(controller);  
    }
   
    public Lookup getLookup(){return this.proxyLookup;}
}


Scott Kaylie wrote:

> My panels cannot subclass TopComponent.  They are subclasses of
> SectionInnerPanel because that is what is required to be returned by
> the InnerPanelFactory.
>
> David Havrda wrote:
>> Yes.  Just have your panel subclass TopComponent.  Everything works
>> fine.  That is though my JPanel is what is returned by the call to
>> MultiViewElement.getVisualRepresentation.
>>
>> Scott Kaylie wrote:
>>
>>> All object representations are JPanels produced by my subclass of
>>> InnerPanelFactory.  Can you add a PaletteController to a JPanel (if
>>> you subclassed it and created a Lookup for it) and would the
>>> windowing system know to look there and create the palette?
>>>
>>>
>>>
>>> David Havrda wrote:
>>>
>>>> Sorry about that.
>>>>
>>>> So in your DesignMultiViewDesc you return a MultiViewElement
>>>> correct?  What class type are you returning there?  I mean you have
>>>> to be returning a JComponent in the getVisualRepresentation
>>>> correct?  In my case my class is just a JPanel extending
>>>> TopComponent.  What are you using?
>>>>
>>>> -dave
>>>>
>>>> Scott Kaylie wrote:
>>>>
>>>>> Thanks David, but as I mention in my original post, I am not
>>>>> subclassing TopComponent (the one being used is created by either
>>>>> my DesignMultiViewDesc or ToolBarMVElement), so I do not have a
>>>>> TopComponent.getLookup() method to override.  So, I need to know
>>>>> 1) what TopComponent (or other object) to add the
>>>>> PaletteController to and 2) how do I add to that component's
>>>>> lookup when I am not overriding it's getLookup() method?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> David Havrda wrote:
>>>>>
>>>>>> Scott Kaylie wrote:
>>>>>>
>>>>>>> How do I add a palette to the Design view of a multiview
>>>>>>> editor?  The Palette API tutorial is very helpful for adding a
>>>>>>> palette to a new TopComponent by creating a new lookup and
>>>>>>> putting a PaletteController instance in it's InstanceContent,
>>>>>>> but I am not subclassing TopComponent and don't know 1) what
>>>>>>> TopComponent to add the PaletteController to or 2) how to add
>>>>>>> the PaletteController to any lookup (i.e. there's no
>>>>>>> lookup.add(Object x) ).
>>>>>>>
>>>>>>> Btw, why isn't there an add(Object x) method for a Lookup?  It
>>>>>>> seems that could make things a lot easier in a bunch of places.
>>>>>>>
>>>>>> Here is what I did.  In my class (extends TopComponent)
>>>>>> constructor I created a PaletteController.  Then in my getLookup
>>>>>> method I did this
>>>>>>
>>>>>>    public Lookup getLookup() {
>>>>>>              if(null == lookup){
>>>>>>            Lookup[] lookups = new
>>>>>> Lookup[]{dobj.getNodeDelegate().getLookup(),
>>>>>>            Lookups.fixed(new Object[]{paletteController, diagram})};
>>>>>>            lookup = new ProxyLookup(lookups);
>>>>>>        }
>>>>>>        return lookup;
>>>>>>    }
>>>>>>
>>>>>> Seems to work ok for me.  Let me know if you have any problems.
>>>>>>
>>>>>> -dave
>>>>>>
>>>>>
>>>>
>>>
>>
>
Loading...