Project-Based Customer Application (Part 2)

Some progress on the project-based customer application. As shown yesterday, you can select one of two types of customers (e.g., "internal" or "external", for example):

But now, you can also set an icon for the customer: that the project node now, instead of a generic project-level icon, has a customer-specific icon, i.e., the image of the particular customer:

I am not necessarily recommending the approach I took. There are probably definitely better ways of doing this.

Anyway, this is what I did. In the "instantiate()" method within the template's iterator, I create folders and an attribute in the System FileSystem, based on the project name and icon set in the wizard:

//Project name set in the project template wizard:
String projName = this.wiz.getProperty("name").toString();
//Project icon set in the project template wizard:
String icon = this.wiz.getProperty("icon").toString();

//Create a "Customers" folder in the SystemFileSystem:
FileObject customersFolder = FileUtil.getConfigFile("Customers");
if (customersFolder == null) {
//Within the "Customers" folder, create a new folder,
//using the name of the project:
FileObject customerFolder = FileUtil.getConfigFile("Customers").createFolder(projName);

//Set the location of the icon as an attribute of the folder:
customerFolder.setAttribute("icon", icon);

Then, in the "ProjectInformation.getIcon", I copy the icon into the System FileSystem, then I find it there, and return it. The last piece of this part of the code is as follows (a lot more comes before it, for the copying of the file from the user's location on disk, into the System FileSystem, via FileUtils.copyFile):

URL imageURL = new URL("nbfs:/SystemFileSystem/" + copiedFo.getPath());
return new ImageIcon(imageURL);

And now each customer in the application has a user-defined customer-specific icon, rather than one hard-coded for the project type.


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« November 2015