|
-
How do I enable Scope's logging?
-
Scope uses the Apache Jakarta commons-logging facade
which uses log4j or jdk1.4 logging if either is available, else
it discards all log output. To see log output, use jdk1.4 or
put log4j on the classpath: in either case, logging will be
enabled.
-
What are Selectors?
-
The idea of Selectors is to identify a property in a
model. They allow access to properties without
compile-time binding to the model's public interface.
Selectors are not intended for direct use by application
developers (who use the public interface of their
model objects to access properties). However, Selectors
exist to support the framework and are typically used indirectly
to setup the View to Model binding (eg to bind an STextField to
the "name" property of a "CustomerModel":
textfield.setSelectorString("name");
-
When do I use BasicModel, and must I subclass it to use Scope?
-
BasicModel is an abstract implementation of
ModelChangeEventSource . It allows subclasses to
notify listeners of changes in their state using fireModelChanged().
(See also the "Collection wrappers" question following).
This is useful for Swing applications in which it
is desirable for the GUI to reflect any changes in
the state of models automatically. However, it is not
a necessity if the application developer is willing
to call SPanel.refresh()
in order to manually force the view to synchronise with the current state of its
bound model.
Implementing ModelChangeEventSource is not necessary
to support the default implementation of servlet views
since they have no way of updating when the model changes
(on the server).
-
What are the Collection wrappers?
-
The collection models in
org.scopemvc.model.collection.*
are full BasicModel implementations that fire
ModelChangeEvents when their contents change.
They should be used in applications that use
BasicModel to implement ModelChangeEventSource.
-
Do I need to know JavaBeans in detail to use Scope?
-
You don't need any great knowledge but note that the
default implementation expects model properties to be
presented as public accessors as per the JavaBeans
spec.
For example, a model implementing:
public String getName();
public void setName(String);
has a read-write String property called "name"
according to the JavaBeans spec.
Similarly, a model implementing:
public int getAge();
has a read-only int property called "age".
Scope understands JavaBeans indexed properties, and
can also work with java.util.List and Object[] models.
-
Does Scope use my getters and setters?
-
Yes, Scope uses public accessors to access model properties.
-
How do I decide what to put in a Controller?
-
In a Swing context, think of each Controller
looking after a single View. It seems to work
out that way very well, although it is possible
for a Controller to handle multiple views (see
samples.swing.multiview ).
Controllers are responsible for the sequencing of
application functionality in response to user
interaction. Controllers are the entities that
decide which view a user should see next. For
example, a Controller will respond to a
FIND_CUSTOMER Control
by asking its model to do the search,
and then showing a Search Results View
if some results were found, else a message view if no results
were found, else an error screen if something bad
happened while doing the search.
Controllers are therefore very lightweight, with all
the hard processing going on in the models,
and all the hard look and feel work going on in
the views.
In a servlet application, a Controller looks after a single
ServletView which contains a set of Pages that represent
all the individual HTML pages that the Controller manages.
This is slightly different to the Swing case because Scope
models a servlet application as having all its views
accessible (since the user is free to bookmark pages
etc and the Controller is not necessarily in control of
which page the user is interacting with). However, the
principle that a Controller is responsible for a small
area of self-contained functionality still holds, and the
source code is very similar in either case.
-
How do I configure Scope?
-
There are a few interesting config options available (check the defaults in
org.scopemvc.util.DefaultScopeConfig ). Any of these
defaults can be overriden by application code:
- In your application's startup call:
ScopeConfig.setPropertiesName("myConfig");
with the name of your custom config resource bundle,
- Provide your custom resource bundle (eg "myConfig.properties")
on your application's classpath,
- Add your own definitions of any config property: your definition
overrides the default.
-
How do I set the size of my Scope Swing Application?
-
One method is to call
setViewBounds() in the primary view SPanel.
For example:
this.setViewBounds(new Rectangle(1024,768));
Since the default behaviour (in the SwingContext class) is to
pack the view being shown to its preferred size, another method
is to set a Border of the desired size and apply it to the main SPanel
view of your application. For example:
public class PrimaryView extends SPanel {
private JPanel mainpanel;
private JLabel lab;
public PrimaryView () {
Border b = new EmptyBorder(200,200,200,200);//set the desired size
this.setBorder(b);//assign the sized border to the main view
lab = new JLabel("TEST");
mainpanel = new JPanel();
mainpanel.setLayout(new BorderLayout());
mainpanel.add(lab);
this.add(mainpanel);
}
}
-
How do I make a view's window appear in the default location all the time?
-
Override
getViewBounds() in the view/SPanel to return null.
Otherwise the default implementation saves the state of the view when it is
hidden so it can restore it to the same state when next shown.
-
How do I validate a textfield according a specific Java type?
-
STextField and all view components automatically validate entries against the
bound property type. In the model for a view, set the variable type for your STextField's
bound property to the datatype you want to validate for. If you bind to a
BigDecimal, the STextfield will validate for numeric values and report an error
if the entered data is incorrect. If you enter something wrong it should turn
pink and the tooltip should also be pink and describe the validation error.
STextfield uses the StringConvertor objects of the framework: you can see
the available convertors in org.scopemvc.util.convertor.* .
You can also add new StringConvertors by adding custom convertor classes to
the ScopeConfig.
-
How do I set the default window closing behavior to exit the application
if I close the application window?
-
In the application's SPanel override
getCloseControl()
as follows:
public Control getCloseControl() {
return new Control(BasicController.EXIT_CONTROL_ID);
}
EXIT_CONTROL_ID is recognised by
BasicController to perform a reasonable default
implementation to shut down an application if sent into a
Controller.
When a sub-controller issues this Control, the default implementation
will propogate it up the chain of responsibility, and if unhandled the
application will exit when the Control reaches the topmost Controller
by calling the current ViewContext.exit() , which
for SwingContext simply calls
System.exit(0) (and is ignored by the ServletContexts ).
So if you want to use this Control to simply shut down a subcontroller
rather than the whole application, recognise it and handle it yourself
(for instance to make the subcontroller commit suicide and remove itself
from the chain of responsibility).
-
How do I change the window icon from the built-in Scope icon to my own icon?
-
The icon used for JFrames/JDialogs is picked up from Scope's
configuration. The config key is
org.scopemvc.controller.swing.SwingContext.window_icon
and the default value is
/org/scopemvc/images/window_icon.gif
which is supplied in the Scope distribution.
To change this default icon, you need to:
- package the image in the same jar as your application classes.
- change the value from the above config key in scope.properties
to match the path of the icon file in the jar.
- tell Scope how to locate the jar containing the image resource, by calling
org.scopemvc.util.ResourceLoader.setClientClassLoader(getClass().getClassLoader()) from your application code.
-
How do I sort Swing Tables, Lists or Combos?
-
Sorting is handled by the underlying
org.scopemvc.view.swing.SAbstractListModel
from which SListModel ,
SComboBoxModel and STableModel
are derived. Call
setSorted(boolean)
to enable/disable sorting
if the objects being shown in the list implement
java.util.Comparable ,
else provide a custom java.util.Comparator to
setSorted(Comparator)
For an example, see the SearchResultsView of the "filefind" sample.
|