Set up Latex in Debian Wheezy

1) Using Synaptic Package Manager to install texlive packages and textworks editor

2) If using multirow.sty, need to install texlive-latex-extra package, and run the following command: >sudo texhash

3) For true type fonts,

3.1) create a new directory in /usr/share/fonts/truetype/<yourfontdir>: >sudo mkdir <yourfontdir>

3.2) copy all .ttf into the newly-created directory: >sudo mv *.tff /usr/share/fonts/truetype/<yourfontdir>/

3.3) run the following command: >sudo fc-cache -f -v

4) Run the texworks using XeLatex

Posted in Uncategorized | Leave a comment

Assign MySQL Root Password Using XAMMP Security Page

A fresh installed MySQL has a blank password. So, my scenario is that my MySQL server was installed by XAMPP 1.8.1, and I wanted to assign a root password to it. Instead of doing that in a traditional way, I chose to use XAMPP Security Page.

  1. Open XAMPP Control Panel
  2. Start Apache Server and MySQL Server
  3. Open a Web browser and point to the address: http://localhost/security
  4. Change the Language to English.
  5. Click on the link http://localhost/security/xamppsecurity.php on that page.
  6. Enter the new root password for MySQL
  7. Check on http radio button for the phpMyAdmin authentication
  8. Click on Password changing button
  9. Point browser to the address http://localhost/phpmyadmin/, you will be presented with a pop-up window for entering username and password
  10. enter “root” as a username, and whatever that you just set it up for password.
Posted in Uncategorized | Leave a comment

XAMPP 1.8.1: Cannot start Tomcat server using XAMPP Control Panel

My situation is that I was installing XAMPP 1.8.1 in Windows 8 Professional. After finished the installation, I used XAMPP Control Panel to successfully start Apache Server, MySQL Server, and Tomcat Server, respectively.

The problem was that after I stopped all those services and tried to restart them again using XAMPP Control Panel, the Tomcat server could not be started.

Problem: there is an error in the catalina_start.bat in the $XAMPP_HOME directory. So, the script cannot find the CATALINA_HOME. There are two alternative ways to fix this problem.

Fix #1: Use a text editor to edit the catalina_start.bat in the $XAMPP_HOME directory. Search for:

echo.
echo [XAMPP]: Using JDK
set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

and change it to

echo.
echo [XAMPP]: Using JDK
cd..
set "CURRENT_DIR=%cd%"
set "CATALINA_HOME=%CURRENT_DIR%\tomcat"

Fix #2: Change the path in the Start In properties of the XAMPP Control Panel shortcut icon on the Desktop.

  1. Right click on the XAMPP Control Panel shortcut icon on the Desktop to open a context menu
  2. Click on Properties
  3. Change the Start in path from d:\myxampp\tmp\ to d:\myxampp\
  4. Click Apply and OK buttons
Posted in Uncategorized | Leave a comment

Netbeans IDE 7.2.1: Cannot load platform/lib/nbexec.dll module

I encountered the following error message: cannot load platform/lib/nbexec.dll module, when I installed Netbeans IDE 7.2.1 in Windows 8 Professional with jdk 1.7.0_09.

To fix this problem, right click on the Netbeans IDE shortcut icon on the Desktop, click on Properties, and change path in the “Start in” box from


"C:\Program Files\NetBeans 7.2.1"

to


"C:\Program Files\NetBeans 7.2.1\bin"

Posted in Uncategorized | Leave a comment

Hide/show a Save button in Netbeans Platform 7

When we incorporate NetBEANS Platform 7 into our application, we usually employ Action Annotations rather than layer.xml file for registering actions into a system.

For example, the code below is an implementation of closing a TopComponent. (Notes: we create a PaymentEditorTopComponent.class in org/editor/payment package, and CloseWindowAction.class in the org/action/payment package.)


@ActionID(category = "MyPaymentEditorToolbars_WindowActions",
id = "org.action.payment.CloseWindowAction")
@ActionRegistration(iconBase = "org/action/payment/cross.png",
displayName = "#CTL_CloseWindowAction")
@ActionReferences({
@ActionReference(path = "Toolbars/MyPaymentEditorToolbars_WindowActions", position = 300)
})
@Messages("CTL_CloseWindowAction=Close Window")
public final class CloseWindowAction implements ActionListener {

@Override
public void actionPerformed(ActionEvent e) {
// TODO implement action body
PaymentEditorTopComponent tc = (PaymentEditorTopComponent)WindowManager.getDefault().findTopComponent("PaymentEditorTopComponent");
if (tc.canClose()) {
tc.close();
}
}
}

Then, we add the following code snippets into componentActivated() and componentDeactivated() of the PaymentEditorTopComponent class.


@Override
protected void componentActivated() {
Toolbar toolbar = ToolbarPool.getDefault().findToolbar("MyPaymentEditorToolbars_WindowActions");
if (!toolbar.isVisible()) {
toolbar.setVisible(true);
}
}

@Override
protected void componentDeactivated() {
Toolbar toolbar = ToolbarPool.getDefault().findToolbar("MyPaymentEditorToolbars_WindowActions");
if (toolbar.isVisible()) {
toolbar.setVisible(false);
}
}

By the above means, the Close Window toolbar will be displayed when the PaymentEditorTopComponent is active, and hidden when the PaymentEditorTopComponent is not active.

There is catch. From my understanding, to be able to have Action Annotation as above, the action class must implement ActionListener.

However, the Save button implements SaveCookie, not ActionListener. So, what could we do to hide and show the Save button?

What I have done is to go back to the layer.xml approach.

  1. I create a class file named MySavePaymentCookieImpl which implements SaveCookie as usual.
  2. I have InstanceContent, and fire(boolean){} as shown in the CRUD tutorial
  3. I add the following code into layer.xml

  4. <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
    <filesystem>
    <folder name="Toolbars">
    <folder name="MyPaymentEditorToolbars_WindowActions">
    <file name="org-openide-actions-SaveAction.shadow">
    <attr name="originalFile" stringvalue="Actions/System/org-openide-actions-SaveAction.instance"/>
    <attr name="position" intvalue="300"/>
    </file>

    <file name="org-openide-actions-SaveAllAction.shadow_hidden"/>
    </folder>
    </folder>
    </filesystem>

  5. Now, the key step is to inform the system to use layer.xml file by adding the following line into Module Manifest file

    OpenIDE-Module-Layer: org/editor/payment/layer.xml
Posted in Uncategorized | Leave a comment

Store image into and load image from JavaDB using EclipseLink

My successful experience on how to store and load an image (.jpg) using JavaDB+EclipseLink+Java 1.6.0_25 and NetBeans 7.0 is as follows.

  1. A table named, Customer, is used as an illustrating example. There are three attributes in this table: CustomerId, Name, and Photo.
  2. An SQL script of this table is shown below:


    create table APP.Customer
    (
    CUSTOMER_ID INTEGER not null primary key generated always as identity (start with 1, increment by 1),
    FIRST_NAME VARCHAR(255),
    PHOTO BLOB(2147483647)
    )

  3. Create a database named, CustDB, through the Services tab of NetBeans IDE.
    1. In NetBeans IDE 7.0, click on the Services tab.
    2. Right-click on the JavaDB node, and then click on Create Database…
    3. Enter the database name, user name and password in the provided text boxes. Use “mydb” for the user name and password.
  4. Create a new connection to the newly-created database.
    1. On the “Services” tab, right-click on the “Databases” node, and then click on “New Connection…”
    2. We will use JavaDB Network for this tutorial, so select “JavaDB (Network)” for the driver. Then, click Next.
    3. Enter Host Name: localhost, Port: 1527, Database: CustDB, User name: mydb, and Password: mydb.
    4. Click Next
    5. Select “APP” as the schema name
    6. Click Finish
    7. A new connection node: jdbc:derby:localhost:1527/CustDB [myapp on APP]
  5. Create a new table in CustDB
    1. Expand the CustDB connection node
    2. Expand the APP node under CustDB node
    3. Right-click on the “Table” node under the CustDB/APP node, and click on “Execute Command…” to open an SQL window
    4. Copy the SQL script shown above into the SQL window, and click “Execute” icon.
  6. Create Java Library Project
    1. On the Netbeans IDE 7.0 menu, File –> New Project
    2. Categories: Java and Projects: Java Class Library
    3. Click Next
    4. Project Name: MyCustomerLibraryProject
    5. Click Finish
    6. On the Project tab, right-click on the MyCustomerLibraryProject node –> New –> Entity Classes from Databases …
    7. Select the CustDB connection that is just created above for the Database Connection. Then, there should be only one available table, named Customer.
    8. Click “Add All” and then click “Next”
    9. Put “demo” as the package name, and then click “Finish”
  7. Modify the generated Customer.class file in the MyCustomerJavaLibraryProject
    1. Click the “demo” node to expand the node, there will be one Java file named, “Customer.java”.
    2. Click the file to open it in the NetBeans IDE editor.
    3. Since we use “mydb” as user name and password, we need to use a fully-qualified name for the table name. So, change:


      @Table(name = "CUSTOMER")

      to


      @Table(name = "APP.CUSTOMER")

      The reason is that JavaDB will presume that the user name, in this case “mydb”, is the schema name, however, we create the Customer table in “APP” schema. As a result, we need to use a fully-qualified name for the Customer table which is “APP.CUSTOMER”.

    4. In JavaDB, EclipseLink maps “BLOB” SQL data type into “Serializable” Java SQL data type. However, to store an image, we need to use “byte[]” Java SQL data type. Accordingly, we need to change:
      • The data type of “photo” variable definition from Serializable to byte[].

        @Lob
        @Column(name = "PHOTO")
        private Serializable photo;

        to

        @Lob
        @Column(name = "PHOTO")
        private byte[] photo;
      • The returned data type of getPhoto() method from Serializable to byte[]

        public Serializable getPhoto() {
        return photo;
        }

        to

        public byte[] getPhoto() {
        return photo;
        }
      • The parameter data type of setPhoto() from Serializable to byte[]

        public void setPhoto(Serializable photo) {
        this.photo = photo;
        }

        to

        public void setPhoto(byte[] photo) {
        this.photo = photo;
        }

    5. Now, we are ready to generate MyCustomerLibrary.jar by right-clicking on the “MyCustomerLibraryProject” and then click “Clean and Build”
  8. Create a Library Wrapper module containing “MyCustomerLibraryProject.jar” created above. Then, set the dependencies of this module to DerbyClient and EclipseLink library wrapper modules. Assume that these two modules are created beforehand.
  9. Now, in a Java code where we need to save an image from JLabel into our CustDB database in JavaDB, use the following code snippet.


    //Store image from jLabel into JavaDB
    Customer newCustomer = new Customer();
    ImageIcon imgIcon = (ImageIcon) jLabelImage.getIcon();

    if (imgIcon != null) {

    Image img = imgIcon.getImage();
    byte[] imgByte = getByteArrayFromImage(img);

    newCustomer.setPhoto(imgByte);

  10. The getByteArrayFromImage() method is defined as follows.


    private byte[] getByteArrayFromImage(Image img) {

    byte[] imgByte = null;

    try {
    int imgWidth = img.getWidth(null);
    int imgHeight = img.getHeight(null);
    int imgType = BufferedImage.TYPE_INT_ARGB; // you can experiment with this one
    BufferedImage bi = new BufferedImage(imgWidth, imgHeight, imgType);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, 0, 0, null);
    g2.dispose();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (ImageIO.write(bi, "JPEG", baos)) {
    imgByte = baos.toByteArray();
    }

    } catch (IOException ex) {
    Exceptions.printStackTrace(ex);
    }

    return imgByte;

    }

  11. In addition, for the Java code where an image is loaded from CustDB and displayed in JLabel, use the following code snippet:


    //For image from database to jLabel
    Customer existingCustomer = getCustomerFromDB(customerID);//load a Customer object from database
    byte[] imageByte = existingCustomer.getPhoto();
    if (imageByte != null) {

    ImageIcon imageIcon = new ImageIcon(imageByte);
    java.awt.Image img = imageIcon.getImage();

    this.jLabelImage.setIcon(imageIcon);
    this.jLabelImage.setText(null);

    }

  12. That’s pretty much all we need to do. However, you may need to specify allowable image file types, and scale an image before putting in a JLabel.
  13. The methods in steps #9, #10 and #11 can be used for MySQL database. The thing is that MySQL maps BLOB SQL data type into byte[] Java SQL data type. Therefore, we do not need to do step #7.
  14. The most important steps are #7, #9, #10 and #11 that we need to modify Customer.java file and define save/load methods.

Have fun!

Posted in Uncategorized | 5 Comments

CRUD NetBeans Platform Application with Embedded JavaDB

If you guys have followed this tutorial: CRUD tutorial for NetBeans Platform 7.0, and tried to make it an Embedded JavaDB application based on the following tutorial: Embedded Database for NetBeans Platform CRUD, and you receive this Table/View does not exist. error message, you need to edit a persistence.xml file as follows.

After creating entity classes from database, edit a persistence.xml file by adding:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

into the file within the existing <properties></properties> tags as shown below. (Notes: add the above line to persistence.xml before you create a dist folder).


<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:CustDB;create=true"/>
<property name="javax.persistence.jdbc.password" value="app"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.user" value="app"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>

Next, you just do the “Clean and Build All” to create a “dist” folder containing a “.jar” file. The .jar file will then be used for the CustomerLibrary wrapper module.

In my understanding, the reason is that the create=true property in the connection string URL, jdbc:derby:CustDB;create=true, will only create a new database, but does not create tables.

In addition, when making a connection using Services tab, a new database is created in $NetBeans_Home/.netbeans/7.0/derby. However, when creating a database from running the application, the database is created in $Project_Home or DBManager folder (Click the Files tab to see a newly-created database).

That’s why we still see tables existed when using Services tab, but the application issues “Table/View does not exist.” error message.

Cheers….

Posted in Uncategorized | 16 Comments

Intermodule Communications in NetBeans Platform: Open a TopComponent in one module from another TopComponent in another module through the use of Lookup API

In this blog, I’d like to share my experience on an implementation of a NetBeans Platform application. The content below is mostly based on the CRUD tutorial with some of my own modifications. The key idea is on how to use Lookup API for intermodule communications, specifically, for opening a TopComponent in one module from within another TopComponent in another different module without setting up a direct dependency between two of them. Observe the differences of how the Lookup API is used in the ContractTC and in the ContractSummaryTC. So, have fun!

The scenario for this blog is that:

  • I am developing a NetBeans Platform application containing one data class called Contract and three user-interface (UI) windows named: MainTC, ContractTC and ContractSummaryTC.
    • Contract is a POJO class that contains methods and a number of attributes describing a contract such as contract_number, contract_date, and so on. It is created in its own module named Contract module.
    • MainTC is an entry point of an application. Here, a user can specify whether to create a new contract, or to display information of an existing contract.
    • ContractTC is a user-interface window that contains Form fields (JTextFields) for a user to enter information of a new contract.
    • ContractSummaryTC is a user-interface window that contains Swing components (JTextFields) displaying information of an existing contract.
  • Each UI window is created as a TopComponent in its own module. In other words, MainTC is created in main_editor module, ContractTC is created in contract_editor module, and ContractSummaryTC is created in contract_summary_editor module.
  • A user can go from
    • MainTC to ContractTC for entering contract information to create a new contract.
    • MainTC to ContractSummaryTC for displaying an existing contract information including its payment plan based on contract_number provided by a user.
    • ContractTC to ContractSummaryTC for displaying information of the newly-created contract such as the contract itself and its payment plan.
  • ContractTC requires the last contract number from MainTC in order to generating a new contract number.
  • ContractSummaryTC requires a Contract class object from MainTC. The Contract class object is retrieved from a database by using the contract number specified by a user at the MainTC.
  • ContractSummaryTC requires a Contract class object from ContractTC. The Contract class object is a new contract created from information provided by a user in ContractTC.

Use Case #1: Create a new contract.

  1. In MainTC, a user clicks on the “Create a new contract” button.
  2. The system finds the last contract number in a database.
  3. The system generates a new contract number based on the last contract number found.
  4. The system opens the ContractTC window with a new contract number.
  5. In ContractTC window, the user enters all necessary information for a new contract.
  6. The user clicks on the “Save” button.
  7. Go To Use Case #2

Use Case #2: Display information of a newly-created contract.

  1. Continued from Use Case #1.
  2. The system derives a payment plan for the new contract based on user-provided information.
  3. The system opens the ContractSummaryTC window with contract information and its derived payment plan.

Use Case #3: Display information of an existing contract.

  1. In MainTC, a user provides a contract number, and click on the “Find contract” button.
  2. The system searches for a contract in a database based on the contract number.
  3. The system opens the ContractSummaryTC window with information of the contract retrieved from the database.

Implementation guidelines:

  • MainTC, ContractTC, and ContractSummaryTC are in separate modules. For a loosely-coupling reason, we will not set dependency on any pair of these modules. However, all of them have direct dependencies on the Contract module.
  • When creating a new contract, MainTC will add a new contract number into its lookup, and open the ContractTC window. Then, the ContractTC window has to look for the new contract number in the lookup of the MainTC, when it is opened.
  • When displaying an existing contract, MainTC will add a contract class object into its lookup, and open the ContractSummary window. In addition, the ContractSummary window will have to look for a contract class object in the lookup of the MainTC, when it is opened.
  • When displaying a newly-created contract, ContractTC will add a newly-created contract class into its lookup, and open the ContractSummary window. Moreover, the ContractSummary window will look for a contract class object in the lookup of the ContractTC, when it is opened.

MainTC implementation:

  1. Declare InstanceContent variable as an instance variable. The InstanceContent is a dynamic object class that allows modifications of the content in a lookup.

    private InstanceContent content;

  2. Instantiate the InstanceContent variable in the MainTC constructor.

    content = new InstanceContent();

  3. Put the InstanceContent variable into the lookup of the MainTC by adding the following line after the line above in the MainTC constructor.

    associateLookup(new AbstractLookup(content));

  4. In a method in MainTC class that contains a new contract number, add the following lines to add the new contract number to the dynamic object in the lookup and to open the ContractTC window.

    String contractNumber = generateANewContractNumber();
    //Open the ContractTC window where "ContractTC" is its Preferrred_ID.
    TopComponent tc = WindowManager.getDefault().findTopComponent("ContractTC");
    this.content.add(contractNumber);
    if (tc != null) {
       tc.open();
       tc.requestActive();
    }
    this.content.remove(contractNumber);

  5. In a method in MainTC that contains an existing contract class object, add the following lines to add the object to the lookup of MainTC and to open the ContractSummaryTC window.

    Contract contractObj = retrieveContractFromDatabase(contractNumber);
    TopComponent tc = WindowManager.getDefault().findTopComponent("ContractSummaryTC");
    if (tc != null) {
       tc.open();
       tc.requestActive();
    }
    this.content.add(contractObj);
    this.content.remove(contractObj);


    Note #1: I add the contract class object to the lookup of MainTC after I open the ContractSummaryTC window, and then remove the object from the lookup of MainTC. I do not know the reason, but if I add the contract class object to the lookup of MainTC before I open the ContractSummaryTC window, it does not work.
    Note #2: The above implementations are pretty much what we need to do for adding things to the lookup of a TopComponent (MainTC) in one module. So, other modules can use them.
    Note #3: In summary, we add a contract number as String data type and a contract object as Contract class type to the lookup of MainTC. The first is for ContractTC and the later is for ContractSummaryTC.

ContractTC implementation:

  1. Modify the ContractTC class signature to implement LookupListener as shown below.


    public final class ContractTC extends TopComponent implements LookupListener {
    ...
    ...
    }

  2. Declare a Contract object as an instance variable.

    Contract contractObj=null;

  3. Declare a Lookup.Result variable as an instance variable.

    private Lookup.Result result = null;

  4. Declare an InstanceContent variable as an instance variable.

    private InstanceContent content = null;

  5. Add DocumentListener to JTextFields for save functionality in the constructor.

    this.jTextFieldContractNumber.getDocument().addDocumentListener(new DocumentListener(){
      @Override
      public void insertUpdate(DocumentEvent e) {
        fire(true);
      }
      @Override
      public void removeUpdate(DocumentEvent e) {
        fire(true);
      }
      @Override
      public void changedUpdate(DocumentEvent e) {
        fire(true);
      }
    });

  6. Declare a SaveCookie variable as an instance variable.

    private SaveCookie impl = null;

  7. Instantiate the SaveCookie

    impl = new SaveCookieImpl();

  8. Instantiate the InstanceContent variable in the constructor

    content = new InstanceContent();

  9. Put the InstanceContent object into the lookup of the ContractTC.

    associateLookup(new AbstractLookup(content));

  10. Define an inner private class named SaveCookieImpl that implements SaveCookie interface.


    private class SaveCookieImpl implements SaveCookie {
      @Override
      @SuppressWarnings("unchecked")
      public void save() throws IOException {
      //Implement this method.
      }

  11. Implement the save() method in the SaveCookieImpl class.


    @Override
    @SuppressWarnings("unchecked")
    public void save() throws IOException {
      Confirmation message = new NotifyDescriptor.Confirmation("Do you want to save changes?",
    NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
      Object result = DialogDisplayer.getDefault().notify(message);
      if (NotifyDescriptor.YES_OPTION.equals(result)) {
        fire(false);
        //Obtain contract information from user interface such as JTextFields.
        //Create a contract class object from the obtained information.
        contractObj=createContractObjFromObtainedData();
        //May save the contract class object into a database.
        //Open the ContractSummaryTC window below.
        TopComponent tc = WindowManager.getDefault().findTopComponent("ContractSummaryTC");
        if (tc != null) {
          tc.open();
          tc.requestActive();
        }
        content.add(contractObj);
        content.remove(contractObj);
      }
      else
      {
        javax.swing.JOptionPane.showMessageDialog(null, "Unsuccessfully add a new contract.");
      }
    }

  12. Implement the fire() method that is called in the save() method above.

    public void fire(boolean modified) {
      if (modified) {
        //If the text is modified,
        //we add SaveCookie impl to Lookup
          content.add(impl);
        } else {
        //Otherwise, we remove the SaveCookie impl from the lookup
          content.remove(impl);
        }
      }
    }

  13. Override the componentOpened() method as follows.

    result = WindowManager.getDefault().findTopComponent("MainTC").getLookup().lookupResult(String.class);
    result.addLookupListener(this);
    resultChanged(new LookupEvent(result));

  14. Override the componentClosed() method as follows.

    result.removeLookupListener(this);
    result = null;

  15. Override the componentDeactivated() method as follows.

    @Override
    protected void componentDeactivated() {
      this.content.remove(contractObj);
    }

  16. Override the resultChanged() method as follows.

    @Override
    @SuppressWarnings("unchecked")
    public void resultChanged(LookupEvent le) {
      Lookup.Result r = (Lookup.Result) le.getSource();
      Collection col = r.allInstances();
      if (!col.isEmpty()) {
        for (String contractNumber : col) {
          this.jTextFieldContractNumber.setText(contractNumber);
          //Do anything that you would like to.
        }
      }
    }

ContractSummaryTC implementation:

  1. Define two LookupListener classes as private inner classes. These two custom classes are used to detect changes of the content in the lookups of MainTC and ContractTC, respectively.


    private class MyMainTCLookupListener implements LookupListener {
      @Override
      @SuppressWarnings("unchecked")
      public void resultChanged(LookupEvent le) {
        Lookup.Result r = (Lookup.Result) le.getSource();
        Collection col = r.allInstances();
        if (!col.isEmpty()) {
         for (ContractT cont : col) {
          jTextFieldContractNumber.setText(cont.getContractNumber());
          jTextFieldContractDate.setText(cont.getContractDate());
          //Retrieve payment history, or
          //Do something else as you would like to.
         }
        }
       }
    }


    private class MyContractTCLookupListener implements LookupListener {
      @Override
      @SuppressWarnings("unchecked")
      public void resultChanged(LookupEvent le) {
        Lookup.Result r = (Lookup.Result) le.getSource();
        Collection col = r.allInstances();
        if (!col.isEmpty()) {
         for (ContractT cont : col) {
          jTextFieldContractNumber.setText(cont.getContractNumber());
          jTextFieldContractDate.setText(cont.getContractDate());
          //Generate a payment plan, or
          //Do something else as you would like to.
         }
        }
       }
    }

    Note: The reason I define two separate LookupListener classes is that I can differentiate where or which class the Contract object is coming from. For example, if a contract object is from MainTC, I know that the contract is retrieved from the database. Accordingly, I can further retrieve payment history for this contract. In contrary, if a contract object is from ContractTC, I know that it is a newly-created contract. So, I can further implement a generation of payment plan for this contract.

     

  2. Declare two LookupListener variables as instance variables.

    private MyMainTCLookupListener mainTCLookupListener;
    private MyContractTCLookupListener contractTCLookupListener;

  3. Declare two Lookup.Result variables as instance variables.

    private Lookup.Result mainTCLookupResult;
    private Lookup.Result contractTCLookupResult;

  4. Instantiate LookupListener variables in the constructor.


    mainTCLookupListener = new MyMainTCLookupListener();
    contractTCLookupListener = new MyContractTCLookupListener();

  5. Override the componentOpened() method as follows.

    mainTCLookupResult = WindowManager.getDefault().findTopComponent("MainTC").getLookup().lookupResult(ContractT.class);
    mainTCLookupResult.addLookupListener(mainTCLookupListener);
    contractTCLookupResult = WindowManager.getDefault().findTopComponent("ContractTC").getLookup().lookupResult(ContractT.class);
    contractTCLookupResult.addLookupListener(contractTCLookupListener);

  6. Override the componentClosed() method as follows.

    mainTCLookupResult.removeLookupListener(mainTCLookupListener);
    mainTCLookupResult = null;
    contractTCLookupResult.removeLookupListener(contractTCLookupListener);
    contractTCLookupResult = null;

Posted in Uncategorized | 2 Comments

Drupal 7 (RC2): How to create a customized front page.

In this blog, I briefly describe a procedure for creating a customized Drupal front page. It’s just a series of steps of what to do, not a detailed how-to.

  1. Get into the theme directory: $Drupal7_Home/sites/all/themes/danland, where “danland” is the theme name.
  2. Copy and paste page.tpl.php into the same directory as it already is.
  3. Rename the copied file to page--front.tpl.php. Notice that there are two dashes.
  4. Change whatever you’d like to do for your customization in the page--front.tpl.php. For example, for a testing purpose, I change the phrase “Theme by” at the bottom of the page to “Developed by”.
  5. Clear Drupal caches:
    1. Open a web browser and point the address to your Drupal homepage such as http://localhost/drupal7
    2. Log into your Drupal homepage as administrator.
    3. Click on “Configuration”
    4. Then, under the “Development” section, click on “Performance”
    5. Finally, click on “Clear all caches”.
  6. Refresh your Drupal homepage, the “Theme by” at the button of the homepage should be changed to “Developed by”.

Let’s try to customize Acquia Marina theme as I explain in this blog.

Posted in Uncategorized | 10 Comments

Fix incorrectly-displayed column names when creating a custom JTableModel that extends AbstractTableModel.

When we write a custom JTable that extends AbstractTableModel, its column names may not be displayed correctly if we forget to override a particular method. By the “incorrect display”, I mean that instead of showing names of the columns specified in the custom class, the column names were displayed as “A”, “B”, “C”, … 

To fix this problem, we need to implement getColumnName() in our custom TableModel. This method is not required for extending AbstractTableModel. So, some of us may not do it.

For example, if we define column names of a table as

String[] columnNames={"name1", "name2"};

Then, we can override the getColumnName(int columnIndex) as


public String getColumnName(int columnIndex){
return columnNames[columnIndex];
}

Well, do not get confused between:
getColumnNames() and getColumnName(int columnIndex).

Posted in Uncategorized | Leave a comment