example adding views dynamically

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

example adding views dynamically

Ernest Micklei-2
Hi,

I am looking for a small example
that shows how to add a view
dynamically ( i.e. in a method after
opening a shell ) to a composite view.

thanx,
emm


Reply | Threaded
Open this post in threaded view
|

Re: example adding views dynamically

Ian Bartholomew-4
Ernest,
> I am looking for a small example
> that shows how to add a view
> dynamically ( i.e. in a method after
> opening a shell ) to a composite view.

Have a look in the image for methods that, for various reasons, create views
dynamically (FramingLayout class>>example1 is one). I'm pretty sure there
are others but I can't find them at the moment.

Quick example - Image a Shell subclass to which has been give a main view
containing two Container views (named 'left' and 'right') and a couple of
menu commands which send #addLeft and: #addRight.

You could then implement -

====>addLeft
    | left listView |

   ( left := self view viewNamed: 'left')
        backcolor: Color red.

    (listView := left addSubView: ListBox new name: 'leftList')
        position: 8@8;
        extent: 200@200.

    (self add: ListPresenter new name: 'leftList')
        view: listView;
        list: #('tom' 'dick' 'harry').

    (self presenterNamed: 'leftList')
            when: #selectionChanged
            send: #bell
            to: Sound


====>addRight
    | right |

    (right := self view viewNamed: 'right')
        backcolor: Color blue;
        layoutManager: FlowLayout new.

    (right addSubView: PushButton new)
        command: #pushMe1;
        text: 'Push Me1'
    (right addSubView: PushButton new)
        command: #pushMe2;
        text: 'Push Me2'

====>pushMe1
    MessageBox notify: 'Button1'

====>pushMe2
    MessageBox notify: 'Button2'

Is that enough or do you want some more specific examples using particular
classes of View?

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: example adding views dynamically

Bill Schwab-2
In reply to this post by Ernest Micklei-2
Ernest,

> I am looking for a small example
> that shows how to add a view
> dynamically ( i.e. in a method after
> opening a shell ) to a composite view.

In the base system, have a look at
PublishedAspectInspector>>onAspectSelected.  The Pane Holders package on my
web site includes a possibly flawed attempt at generalization to support
scrolled lists along with simple panes.  Start with PaneHolder and then work
up from there.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: example adding views dynamically

Ernest Micklei-2
In reply to this post by Ian Bartholomew-4
Thanx for examples.

However they differ from what I want to achieve
because I do not have an explicit view class for my
presenter.

I have a subclass of Presenter named
WizardStepPresenter and defined a view for it using
the composer. I have a subclass of Shell called WizardShell
and its view has an empty containerview named 'steps'.
Now I want to add the default view of my step presenter
to the containerview of the shell.

So I am trying:

container := self view viewNamed: 'steps'.
step := MyWizardStep new.  "subclass of WizardStepPresenter with a default
view"
stepView := step ???createDefaultView???.
(container addSubView: stepView name: 'mystep') position: 0@0 ;extent:
300@300.


Question is how to create the view to be added to the container and what to
do
with the presenter (step).

Thnx,
Ernest


Reply | Threaded
Open this post in threaded view
|

Re: example adding views dynamically

Ian Bartholomew-4
Ernest,

> I have a subclass of Presenter named
> WizardStepPresenter and defined a view for it using
> the composer. I have a subclass of Shell called WizardShell
> and its view has an empty containerview named 'steps'.
> Now I want to add the default view of my step presenter
> to the containerview of the shell.

Right, Bill's suggestion was closer than mine to what you are trying to
achieve and his pane holder goodie (see
http://needle.anest.ufl.edu/anest4/bills/) might do what you want, or give
you a start anyway.

Another place to look in the Dolphin image is the InspectorShell class which
is used in association with the Inspector class hierarchy. If you want to
inspect an object then an Inspector subclass, a Presenter, is created and
inserted as a sub presenter/view into an instance of InspectorShell.

Try single stepping through "#(1 2 3) inspect" and note the code in
Inspector class>>shellOn:

I've just had a little play and came up with  this (evaluate in a
workspace)-

shell := Shell show.
shell view layoutManager: ProportionalLayout new.
shell view
    addSubView: (ContainerView new
        backcolor: Color red;
        yourself)
    name: 'left'.

shell view addSubView: Splitter new.

shell view
    addSubView: (ContainerView new
        backcolor: Color blue;
        layoutManager: BorderLayout new;
        yourself)
    name: 'right'.

All that does is display a Shell with two Container sub views

right := CompositePresenter new
    view: (shell view viewNamed: 'right');
    yourself.
eas := EtchASketch createIn: right.
eas view arrangement: #center

This bit then creates a CompositePresenter for the right hand view and
inserts another MVP triad, eas, which can now be used as a normal Presenter.
You might have to be a bit careful about what type of Presenter you insert,
Shell subclasses don't appear to like being placed into other shells
although CompositePresenter subclasses (like EtchASketch) are OK.

Any closer?
    Ian