Vaadin TreeGrid has no expand or collapse icon - vaadin

I use Vaadin to create a simple Web Application that contains a single TreeGrid.
The TreeGrid shows up, but there is no handle to expand or collapse a root element ("Year 2010" or "Year 2011") although there are children.
When I use expand(..) Method, the tree is expanded (as shown in the screenshot), but there is no icon to collapse it. In the screenshot below "Year 2011" is the expanded root node where "Customer Project1" and "Customer Project 2" are children.
The project is build with Maven, I use vaadin-bom version 13.0.2 with vaadin-grid-flow-3.0.3.jar.
Below the screenshot there is the code I use. I think the problem must be somewhere in method createTreeGrid().
The working example from Vaadin can be found here
Vaadin example
So anyone any ideas on how to solve this? any help appreciated... :-)
Thorsten
package hello;
#Route
public class MainView extends VerticalLayout
{
public MainView()
{
add( createTreeGrid() );
}
private TreeGrid<Project> createTreeGrid()
{
TreeGrid<Project> treeGrid = new TreeGrid<>();
final List<Project> generateProjectsForYears = generateProjectsForYears( 2010, 2016 );
treeGrid.setItems( generateProjectsForYears, Project::getSubProjects );
treeGrid.addColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );
treeGrid.addColumn( Project::getHoursDone ).setHeader( "Hours Done" );
treeGrid.addColumn( Project::getLastModified ).setHeader( "Last Modified" );
treeGrid.expand( generateProjectsForYears.get( 1 ) ); // works!
return treeGrid;
}
private List<Project> generateProjectsForYears( int startYear, int endYear )
{
List<Project> projects = new ArrayList<>();
for ( int year = startYear; year <= endYear; year++ )
{
Project yearProject = new Project( "Year " + year );
Random random = new Random();
for ( int i = 1; i < 2 + random.nextInt( 5 ); i++ )
{
Project customerProject = new Project( "Customer Project " + i );
customerProject.setSubProjects( Arrays.asList(
new LeafProject( "Implementation", random.nextInt( 100 ), year ),
new LeafProject( "Planning", random.nextInt( 10 ), year ),
new LeafProject( "Prototyping", random.nextInt( 20 ), year ) ) );
yearProject.addSubProject( customerProject );
}
projects.add( yearProject );
}
return projects;
}
private class Project
{
private List<Project> subProjects = new ArrayList<>();
private String name;
public Project( String name )
{
this.name = name;
}
public String getName()
{
return name;
}
public List<Project> getSubProjects()
{
return subProjects;
}
public void setSubProjects( List<Project> subProjects )
{
this.subProjects = subProjects;
}
public void addSubProject( Project subProject )
{
subProjects.add( subProject );
}
public int getHoursDone()
{
return getSubProjects().stream()
.map( project -> project.getHoursDone() )
.reduce( 0, Integer::sum );
}
public Date getLastModified()
{
return getSubProjects().stream()
.map( project -> project.getLastModified() )
.max( Date::compareTo ).orElse( null );
}
}
private class LeafProject extends Project
{
private int hoursDone;
private Date lastModified;
public LeafProject( String name, int hoursDone, int year )
{
super( name );
this.hoursDone = hoursDone;
Random random = new Random();
lastModified = new Date( year - 1900, random.nextInt( 12 ),
random.nextInt( 10 ) );
}
#Override
public int getHoursDone()
{
return hoursDone;
}
#Override
public Date getLastModified()
{
return lastModified;
}
}
}

You have to define a hierarchy column.
So simply replace
treeGrid.addColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );
with
treeGrid.addHierarchyColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );

Related

Right-align column contents in Vaadin Grid?

In the new Vaadin Grid widget (alternative to venerable Table), how does one right-align numbers or other content in a column?
The simplest way I can think of is to define your own CSS classes and style generator, pretty much similar to what I'd had done when working with tables.
#Theme("mytheme")
#Widgetset("com.matritza.MyAppWidgetset")
public class MyUI extends UI {
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
// meh, default stuff
}
#Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
// create a grid
Grid grid = new Grid("Grid test");
// create a specific container for the grid to hold our persons
BeanItemContainer<Person> container = new BeanItemContainer<>(Person.class);
grid.setContainerDataSource(container);
// define our own style generator
grid.setCellStyleGenerator(new Grid.CellStyleGenerator() {
#Override
public String getStyle(Grid.CellReference cellReference) {
if ("age".equals(cellReference.getPropertyId())) {
// when the current cell is number such as age, align text to right
return "rightAligned";
} else {
// otherwise, align text to left
return "leftAligned";
}
}
});
// generate some dummy data
for (int i = 0; i < 10; i++) {
container.addItem(new Person("Name " + i, "Surname " + i, i));
}
layout.addComponent(grid);
}
// basic class to populate the grid in a fast & simple way
public class Person {
private String name;
private String surname;
private int age;
private Person(String name, String surname, int age) {
this.name = name;
this.surname = surname;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}
And the basic CSS styles
#mixin mytheme {
#include valo;
// Insert your own theme rules here
.leftAligned {
text-align: left;
}
.rightAligned {
text-align: right;
}
}
And you should see something like
By the way, in Java 8 and later, the new Lambda syntax for that style generator would be:
grid.setCellStyleGenerator(( Grid.CellReference cellReference ) -> {
if ( "age".equals( cellReference.getPropertyId() ) ) {
// when the current cell is number such as age, align text to right
return "rightAligned";
} else {
// otherwise, align text to left
return "leftAligned";
}
});
One can also use already present styles like v-align-right, v-align-middle, etc. Just see what themes like Valo already contain, and extend existing themes only when needed.
Here's simple example how one could implement cell generator with regexp (matching one or multiple fields based on name of field)
public class RegexpCellStyleGenerator implements CellStyleGenerator {
private String regex = ".*"; // defaults all
String style = "v-align-right"; // default is here just as example
// special version useful only when one wants to style all fields inside grid
public RegexpCellStyleGenerator(String style) {
super();
this.style = style;
}
public RegexpCellStyleGenerator(String regex, String style) {
super();
this.regex = regex;
this.style = style;
}
#Override
public String getStyle(CellReference cellReference) {
String propertyId = cellReference.getPropertyId().toString();
if (propertyId.matches(regex)) {
return style;
}
return null;
}
and as this is only partially useful as most grids have multiple fields composite generator could be handy
public class CompositeCellStyleGenerator implements CellStyleGenerator {
List<CellStyleGenerator> generators = new ArrayList<>();
public CompositeCellStyleGenerator() {}
public void addCellStyleGenerator(CellStyleGenerator generator) {
generators.add(generator);
}
#Override
public String getStyle(CellReference cellReference) {
List<String> styles = new ArrayList<>();
for (CellStyleGenerator generator : generators) {
String style = generator.getStyle(cellReference);
if (style != null) {
styles.add(style);
}
}
if (!styles.isEmpty()) {
return styles.stream().collect(Collectors.joining(" "));
}
return null;
}
Composite generator joins all styles together and can be used like this. If there's multiple styles for one column both are applied.
RegexpCellStyleGenerator yearGenerator = new RegexpCellStyleGenerator("yearOfFoundation", "v-align-right");
RegexpCellStyleGenerator nameGenerator = new RegexpCellStyleGenerator("name", "v-align-center");
RegexpCellStyleGenerator nameGenerator2 = new RegexpCellStyleGenerator("name", "v-label-huge");
CompositeCellStyleGenerator compositeGenerator = new CompositeCellStyleGenerator();
compositeGenerator.addCellStyleGenerator(yearGenerator);
compositeGenerator.addCellStyleGenerator(nameGenerator);
compositeGenerator.addCellStyleGenerator(nameGenerator2);
grid.setCellStyleGenerator(compositeGenerator);
Note that composite generator can use generic generators like one with regexp definitions and more complex use case specific ones.
Hope this helps those who try to find easy way to style cells. Happy Experimenting.

JavaFX TableView TableRow focus behaves strangely

I'm using JDK 1.7.0_51 if that matters. I have the following adapted example code to demonstrate the unusual behaviour that I'm seeing.
I've programmatically selected row 0 in the table, then insert added rows at the 0 position. I'd expect the selected row to shift down by one, but instead it is dropping by two. In addition, when I monitor the focus property on the table row, I see that it changes quite a bit during this addition of a single row. And when it is finished inserting, row 2 has the dark blue background indicating selection, but row 3 has a blue highlighted border. I'm not sure what that is indicating.
I'm currently doing data validation when a table row focus is lost so that I can prevent users from leaving the current entry until it is correctly formed. But this selection and focus behaviour is causing my application to misbehave. This is the simplest test case I was able to create that shows what's happening.
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TableViewTest extends Application
{
private final TableView< Person > table = new TableView< Person >();
private final ObservableList< Person > data =
FXCollections.observableArrayList(
new Person( "Jacob", "Smith", "jacob.smith#example.com" ),
new Person( "Isabella", "Johnson", "isabella.johnson#example.com" ),
new Person( "Ethan", "Williams", "ethan.williams#example.com" ),
new Person( "Emma", "Jones", "emma.jones#example.com" ),
new Person( "Michael", "Brown", "michael.brown#example.com" ) );
final HBox hb = new HBox();
public static void main( String[] args )
{
launch( args );
}
#Override
public void start( Stage stage )
{
Scene scene = new Scene( new Group() );
stage.setTitle( "Table View Sample" );
stage.setWidth( 450 );
stage.setHeight( 550 );
final Label label = new Label( "Address Book" );
label.setFont( new Font( "Arial", 20 ) );
table.setEditable( true );
table.setRowFactory( getRowFactory() );
TableColumn firstNameCol = new TableColumn( "First Name" );
firstNameCol.setMinWidth( 100 );
firstNameCol.setCellValueFactory(
new PropertyValueFactory< Person, String >( "firstName" ) );
TableColumn lastNameCol = new TableColumn( "Last Name" );
lastNameCol.setMinWidth( 100 );
lastNameCol.setCellValueFactory(
new PropertyValueFactory< Person, String >( "lastName" ) );
TableColumn emailCol = new TableColumn( "Email" );
emailCol.setMinWidth( 200 );
emailCol.setCellValueFactory(
new PropertyValueFactory< Person, String >( "email" ) );
table.setItems( data );
table.getColumns().addAll( firstNameCol, lastNameCol, emailCol );
table.getSelectionModel().select( 0 );
table.getSelectionModel().getSelectedCells().addListener( new ListChangeListener< TablePosition >()
{
#Override
public void onChanged( final ListChangeListener.Change< ? extends TablePosition > c )
{
if ( !c.getList().isEmpty() )
{
for ( TablePosition pos : c.getList() )
{
System.out.println( "Row " + String.valueOf( pos.getRow() ) + " selected" );
}
}
else
{
System.out.println( "Row unselected" );
}
}
} );
final TextField addFirstName = new TextField();
addFirstName.setPromptText( "First Name" );
addFirstName.setMaxWidth( firstNameCol.getPrefWidth() );
final TextField addLastName = new TextField();
addLastName.setMaxWidth( lastNameCol.getPrefWidth() );
addLastName.setPromptText( "Last Name" );
final TextField addEmail = new TextField();
addEmail.setMaxWidth( emailCol.getPrefWidth() );
addEmail.setPromptText( "Email" );
final Button addButton = new Button( "Add" );
addButton.setOnAction( new EventHandler< ActionEvent >()
{
#Override
public void handle( ActionEvent e )
{
data.add( 0, new Person(
addFirstName.getText(),
addLastName.getText(),
addEmail.getText() ) );
addFirstName.clear();
addLastName.clear();
addEmail.clear();
}
} );
hb.getChildren().addAll( addFirstName, addLastName, addEmail, addButton );
hb.setSpacing( 3 );
final VBox vbox = new VBox();
vbox.setSpacing( 5 );
vbox.setPadding( new Insets( 10, 0, 0, 10 ) );
vbox.getChildren().addAll( label, table, hb );
( ( Group ) scene.getRoot() ).getChildren().addAll( vbox );
stage.setScene( scene );
stage.show();
}
private Callback< TableView< Person >, TableRow< Person >> getRowFactory()
{
return new Callback< TableView< Person >, TableRow< Person >>()
{
#Override
public TableRow< Person > call( final TableView< Person > arg0 )
{
return new DataTableRow();
}
};
}
public class DataTableRow extends TableRow< Person >
{
private final ChangeListener< Boolean > focusListener = new ChangeListener< Boolean >()
{
#Override
public void changed( final ObservableValue< ? extends Boolean > unused, final Boolean arg1,
final Boolean focused )
{
System.out.println( "Row " + getIndex() + " Focus: " + focused );
}
};
public DataTableRow()
{
focusedProperty().addListener( this.focusListener );
}
}
public static class Person
{
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private final SimpleStringProperty email;
private Person( String fName, String lName, String email )
{
this.firstName = new SimpleStringProperty( fName );
this.lastName = new SimpleStringProperty( lName );
this.email = new SimpleStringProperty( email );
}
public String getFirstName()
{
return firstName.get();
}
public void setFirstName( String fName )
{
firstName.set( fName );
}
public String getLastName()
{
return lastName.get();
}
public void setLastName( String fName )
{
lastName.set( fName );
}
public String getEmail()
{
return email.get();
}
public void setEmail( String fName )
{
email.set( fName );
}
}
}
The output I get from running this and adding a single row is:
Row unselected
Row 1 selected
Row 0 Focus: false
Row 1 Focus: true
Row 1 Focus: false
Row 2 Focus: true
Row unselected
Row unselected
Row 2 selected
Row 2 Focus: false
Row 3 Focus: true
Row 3 Focus: true
Can anyone help me understand what is going on here and whether this is correct behaviour?
What IDE are you using? Have you tried it on IntelliJ? I don't have the focus problem you reported when I run your Class in IntelliJ at all. I'm using jdk 8u20. When I go to a new row, the previous row get de-focused and the new row gets focused. See below:
Row 0 Focus: true
Row 0 Focus: false
Row 1 Focus: true
Row 1 selected
Row 1 Focus: false
Row 2 Focus: true
Row 2 selected
Row unselected
Row 3 selected
Row 2 Focus: false
Row 3 Focus: true
Row 3 Focus: false
Row 4 Focus: true
Row 1 Focus: true
Row 4 Focus: false
Row 1 selected
Row 1 Focus: false
Row 5 Focus: true
Row 5 selected
Row 3 Focus: true
Row 5 Focus: false
Row 3 selected
Row 0 Focus: true
Row 3 Focus: false
Row 0 selected
Row 0 Focus: false
Row 1 Focus: true
Row 1 selected
Row 1 Focus: false
Row 2 Focus: true
Row 2 selected
Row 2 Focus: false
Row 3 Focus: true
Row 3 selected
Row 0 Focus: true
Row 3 Focus: false
Row 0 selected

Null point exception in persistent object , blackberry application

I am using persistent stores to store data in a Blackberry application. I am trying to store phone number in persistent objects, but after storing, it gives null value.
here i am posting my code:
public static Vector push_data;
public static PersistentObject push_store = null;
public static final long KEY = 0x9df9f961bc333daL;
boolean isNumberVerified;
// PasswordEditField password;
static String verifiedPhoneNumber = "number";
public static String phoneNumber;
static String Number = "number";
public Third() {
super(Field.USE_ALL_HEIGHT | Field.FIELD_HCENTER);
System.out.println("******************** Into SplashScreen");
try {
bitmap = Bitmap.getBitmapResource("im.png");
BitmapField bmpField = new BitmapField(bitmap);
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add(bmpField);`
........
public void fieldChanged(Field field, int context) {
if (field == btnNext) {
final String msg = Util.getRandomNumber();
checkIsVerified(Number, msg);
}
}
private void checkIsVerified(final String Number, final String msg) {
Dialog.alert("Verifying " + Number);
if (verifiedPhoneNumber == Number) {
isNumberVerified = true;
Dialog.alert("isverified " + Number);
push_store = PersistentStore.getPersistentObject( KEY );
push_data = (Vector) push_store.getContents();
if( push_data == null ) {
push_data = new Vector();
push_data.addElement("number");
push_store.setContents( push_data );
push_store.commit();
Dialog.alert("isverified " + push_data);
UiApplication.getUiApplication().pushScreen(new spinner());
} else {
isNumberVerified = false;
UiApplication.getUiApplication().pushScreen(new Sms());
}
}
Try this -
public static String push_data="";
public static PersistentObject push_store;
public static final long KEY = 0x9df9f961bc33352L;
//For get contents
push_store = PersistentStore.getPersistentObject( KEY );
push_data = (String) push_store.getContents();
//For set contents
push_data=Number;
push_store.setContents( push_data );
push_store.commit();

Packaging Blackberry OAuth app throwing error

I am creating an application that will post a link onto Twitter. The following code refuses to package up for me, throwing the following error:
Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified
Here is the code:
public class ShowAuthBrowser extends MainScreen implements OAuthDialogListener
{
private final String CONSUMER_KEY = "<Consumer>";
private final String CONSUMER_SECRET = "<Secret>";
private LabelField _labelStutus;
private OAuthDialogWrapper pageWrapper = null;
public StoreToken _tokenValue;
public BrowserField b = new BrowserField();
Manager _authManager;
Manager _pinManager;
ButtonField authButton;
TextField authPin;
public ShowAuthBrowser()
{
_authManager = new VerticalFieldManager(NO_VERTICAL_SCROLL |
NO_VERTICAL_SCROLLBAR);
_pinManager = new HorizontalFieldManager(NO_VERTICAL_SCROLL |
NO_VERTICAL_SCROLLBAR);
authButton = new ButtonField("OK");
authPin = new TextField(Field.EDITABLE);
_authManager.add(_labelStutus );
_authManager.add(b);
_pinManager.add(authButton);
_pinManager.add(authPin);
pageWrapper = new BrowserFieldOAuthDialogWrapper(b,CONSUMER_KEY,
CONSUMER_SECRET,null,this);
pageWrapper.setOAuthListener(this);
add(_pinManager);
add(_authManager);
authButton.setChangeListener( new FieldChangeListener( ) {
public void fieldChanged( Field field, int context ) {
if( field == authButton ) {
doAuth(authPin.getText());
}
}
} );
}
public void doAuth( String pin )
{
try
{
if ( pin == null )
{
pageWrapper.login();
}
else
{
this.deleteAll();
add(b);
pageWrapper.login( pin );
}
}
catch ( Exception e )
{
final String message = "Error logging into Twitter: " +
e.getMessage();
Dialog.alert( message );
}
}
public void onAccessDenied(String response ) {
updateScreenLog( "Access denied! -> " + response );
}
public void onAuthorize(final Token token) {
final Token myToken = token;
_tokenValue = StoreToken.fetch();
_tokenValue.token = myToken.getToken();
_tokenValue.secret = myToken.getSecret();
_tokenValue.userId = myToken.getUserId();
_tokenValue.username = myToken.getUsername();
_tokenValue.save();
UiApplication.getUiApplication().invokeLater( new Runnable() {
public void run() {
deleteAll();
Credential c = new Credential(CONSUMER_KEY,
CONSUMER_SECRET,
myToken);
PostTweet tw = new PostTweet();
String message="Testing BB App";
boolean done=false;
done=tw.doTweet(message, c);
if(done == true)
{
Dialog.alert( "Tweet succusfully..." );
close();
}
}
});
}
public void onFail(String arg0, String arg1) {
updateScreenLog("Error authenticating user! -> " + arg0 + ", " + arg1);
}
private void updateScreenLog( final String message )
{
UiApplication.getUiApplication().invokeLater( new Runnable() {
public void run() {
_labelStutus.setText( message );
}
});
}
}
The odd thing is, if I remove the following lines, it packages just fine:
authButton.setChangeListener( new FieldChangeListener( ) {
public void fieldChanged( Field field, int context ) {
if( field == authButton ) {
doAuth(authPin.getText());
}
}
} );
Any help would be appreciated as I really need the field listener attached to this screen.
With code like authButton.setChangeListener(null), it does package successfully however I do need code with FieldChangeListener to do something.
Make sure your java bin path is set in environment variable.
http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
and take a look at the last 3 posts in the following website:
http://supportforums.blackberry.com/t5/Java-Development/I-O-Error-Cannot-run-program-quot-jar-quot-CreateProcess-error-2/td-p/522638
Also make sure The Java® software development kit (Java SDK/JDK) is installed on the computer, and a correct version of the Java SDK is used.
http://supportforums.blackberry.com/t5/Java-Development/I-O-Error-CreateProcess/ta-p/445949
As mentioned in Scott Boettger comment below, this post could be helpful as well:
http://supportforums.blackberry.com/t5/Java-Development/why-cause-more-then-100-compiled-classes-packaging-I-O-error/m-p/520282

Stuck up with MessageList in Blackberry

I am try to do MessageList in blackberry using midlet, but whatever I do some expection comes up. Right now am getting NullPointerException. Here is the code
EncodedImage indicatorIcon = EncodedImage.getEncodedImageResource("img/indicator.png");
ApplicationIcon applicationIcon = new ApplicationIcon(indicatorIcon);
ApplicationIndicatorRegistry.getInstance().register(applicationIcon, false, false);
ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
MessageListStore messageStore = MessageListStore.getInstance();
if(reg.getApplicationFolder(INBOX_FOLDER_ID) == null)
{
ApplicationDescriptor daemonDescr = ApplicationDescriptor.currentApplicationDescriptor();
String APPLICATION_NAME = "TestAPP";
ApplicationDescriptor mainDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {});
ApplicationFolderIntegrationConfig inboxIntegration = new ApplicationFolderIntegrationConfig(true, true, mainDescr);
ApplicationFolderIntegrationConfig deletedIntegration = new ApplicationFolderIntegrationConfig(false);
ApplicationMessageFolder inbox = reg.registerFolder(MyApp.INBOX_FOLDER_ID, "Inbox", messageStore.getInboxMessages(),
inboxIntegration);
ApplicationMessageFolder deleted = reg.registerFolder(MyApp.DELETED_FOLDER_ID, "Deleted Messages", messageStore.getDeletedMessages(), deletedIntegration);
messageStore.setFolders(inbox, deleted);
}
DemoMessage message = new DemoMessage();
String name = "John";
message.setSender(name);
message.setSubject("Hello from " + name);
message.setMessage("Hello Chris. This is " + name + ". How are you? Hope to see you at the conference!");
message.setReceivedTime(System.currentTimeMillis());
messageStore.addInboxMessage(message);
messageStore.getInboxFolder().fireElementAdded(message);
Can someone suggest me a simple MessageList sample for midlet to just show a String in MessageList and custom ApplicationIndicator value. If possible OnClick of message bring back the midlet from background.
use the following code:
static class OpenContextMenu extends ApplicationMenuItem {
public OpenContextMenu( int order ) {
super( order );
}
public Object run( Object context ) {
if( context instanceof NewMessage ) {
try {
NewMessage message = (NewMessage) context;
if( message.isNew() ) {
message.markRead();
ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
ApplicationMessageFolder folder = reg.getApplicationFolder( Mes
sageList.INBOX_FOLDER_ID );
folder.fireElementUpdated( message, message );
//changeIndicator(-1);
}
Inbox inbox = message.getInbox();
Template template = inbox.getTemplate();
//Launch the mainscreen
UiApplication.getUiApplication().requestForeground();
}
catch (Exception ex) {
Dialog.alert();
}
}
return context;
}
public String toString() {
return "Name of the menu item";
}
}

Resources