Research Log of Web Science Students

Computer Science is not simply programming

Into Day 4

leave a comment »

After linking the search module function to the projects feature, I set out to save the project to the database.

But first I had to setup the client side code for easy RPC. After adding new methods and new “package” objects to transport the data from the browser to the server I can say I have shortened and made my code readable. I guess the number of lines are more or less the same but the code is scattered in the places where they should be. Take for example,

private VerticalPanel buildProjectPanel(){
   VerticalPanel projectPanel = new VerticalPanel();
   TextBox titleTextBox = new TextBox();
   titleTextBox.setText("Project Title");
   titleTextBox.setStylePrimaryName("project_title");
   Label moduleTitleLabel = new Label("Module Title: " + moduleTitle);
   moduleTitleLabel.setStylePrimaryName("module_title");
   projectPanel.add(titleTextBox);
   projectPanel.add(moduleTitleLabel);
   for (int i=0;i<activities.size();i++){
	VerticalPanel activityPanel = new VerticalPanel();
	activityPanel.add(new
            LearningActivityPanelImpl(activities.get(i),activity_ids.get(i)));
	activityPanel.setStylePrimaryName("activity");
	projectPanel.add(activityPanel);
    }
    projectPanel.add(saveButton);
    projectPanel.getElement().setId("content_left");
    return projectPanel;
}

My code went from this which is I think okay readable to….

private VerticalPanel buildProjectPanel(String moduleTitle){
   ProjectPanel projectPanel = new ProjectPanel(moduleTitle);
   for (int i=0;i<activities.size();i++){
      VerticalPanel activityPanel = new VerticalPanel();
      activityPanel.add(new
          LearningActivityPanelImpl(activities.get(i),activity_ids.get(i)));
      activityPanel.setStylePrimaryName("activity");
      projectPanel.add(activityPanel);
   }
   projectPanel.add(saveButton);
   projectPanel.getElement().setId("content_left");
   return projectPanel;
}

… to a more concise form. And it still works! Now this is what I call refactoring!


Highly refactored

After I got that out, I coded saving a project to database using AJAX. Project Forms are for one time fill up only so once you save a project, it’s done and the next thing is throwing it to Projectrix. Which may or may not be a good thing. That’s something I’d have to think about after this blog.

Project saved!

The development console showing some parts of the saved project.

Advertisements

Written by Jose Asuncion

December 23, 2009 at 5:28 pm

Posted in Hardwire

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: