Technical Blog

2 Posts tagged with the swt tag

You might be working on a machine with tons of RAM and still run into the nasty "Java heap space" error in Eclipse, because you are using the 32-bit version of JVM and Eclipse. No matter how much RAM your machine has, you cannot give your Eclipse process more than about 1GB of heap space. Doesn't it suck?

 

The myth says that you can't use a 64-bit Eclipse for developing EP on Windows. I am here today to bust it!

 

Eclipse 3.5 (Galileo) 64-bit

Hacker's Summary

Install both 32-bit and 64-bit versions of JVM. Install 64-bit Galileo. Run your Eclipse with the 64-bit JVM. Set the PDE Target Platform environment to win32 x86, and make it run on your 32-bit JVM.

Install JVM

You will need both 32- and 64-bit versions of JDK installed on your machine. The reason is that we currently use an old version of SWT in CM Client, which is only available on win32 x86, and not on win32 x86_64. Therefore the CM Client should be run on a 32-bit version of JVM. However, the Eclipse itself should be run on the 64-bit JVM.

 

Install Eclipse and Plugins

  1. From the Eclipse Galileo download page, download eclipse-SDK-3.5.2-win32-x86_64.zip.
  2. Extract the archive in your directory of choice.
  3. Append the following to the existing eclipse.ini file inside your eclipse directory. The path after the -vm parameter should point to your 64-bit JVM. Make sure you do not leave any whitespace before or after the parameters.
    -vm
    C:\Program Files\Java\jdk1.6.0_21\bin\javaw.exe
    -vmargs
    -Xmx2048M
    -XX:MaxPermSize=512M
    
  4. Run Eclipse and install m2eclipse, BIRT, WTP, and PMD. See Developers Guide for more details.
  5. Go to Window > Prefrences > Java > Installed JREs. You should have your 64-bit JVM listed. Add your 32-bit JVM as a Standard VM. Press OK to close the Prefrences dialog.
  6. Go to Window > Preferences > Java > Compiler, and set the Compiler compliance level to 1.5.

Set up the Target Platform

  1. Go to Window > Preferences > Java Plug-in Development > Target Platform. Add a new Target Definition. Start off an empty target definition, then add the location of your rcp-target directory. If your EP resides under c:\ep, the rcp-target would be at c:\ep\com.elasticpath.cmclient\rcp-target.
  2. Under the Environment tab, set the following parameters:
  3. Press Finish to end the wizard, and select your newly created target definition to be the active target platform.
    Parameter
    Value
    Operating Systemwin32
    Windowing Systemwin32
    Architecturex86
    JRE name<your 32-bit JVM>

Now you are ready to import all your projects, set up your server, and run your Commerce Manager client. You might need to manually change the Run Configuration for the commerce manager product to use the 32-bit JVM.

 

Eclipse 3.6 (Helios) 64-bit

Hacker's Summary

Do the steps above, on a Helios 64-bit installation. In your env.config point to a 64-bit Galileo. Add the maven dependencies to the Deployment Assembly of the web projects.

Follow the steps above!

Follow all the steps above, but with Helios 64-bit instead. You can download it from this page. Use this update site for BIRT and WTP.

Install a 64-bit Galileo

Currently, our Ant build mechanism only supports Eclipse Equinox plugin version 1.0.x. However, Helios ships with Equinox version 1.1. To keep the Ant mechanism working, you need Galileo installed as well. You won't be running it, though. It will just sit there to be used by the Ant build script.

  1. Download and extract Galileo 64-bit.
  2. In your env.config, set eclipse.home to point to the installation directory of your Galileo installation.
  3. In your env.config, set eclipse.version to 3.5.

 

Add Core Maven Dependencies to Deployments

At this stage, if you try deploying the web projects, you will get ClassNotFoundExceptions, because the Maven dependencies of the com.elasticpath.core project are not deployed by default. You need to manually add those dependencies to your web projects. Right click on the com.elasticpath.core project, and open the properties dialog. Under Deployment Assembly, select Add, then Java Build Path Entries, and then select the Maven Dependencies. You should be able to deploy and run your web projects successfully.

 

See this forum post (requires login) for more details on the problem with WTP deployments in Helios.

0 Comments Permalink

This post walks through adding filtering to the System Configuration page in the CM Client helping you track down a setting as quickly as possible.

 

We added the Settings Framework in Elastic Path Commerce 6.1 and it's proved incredibly useful in centralizing configuration and easing customization versus the previous XML based approach.  The number of settings out-of-the-box continues to grow plus any additional ones that customers are free to add.  So this tip will show you how to reign in that growing number of settings.

 

Here's a screenshot of what we'll be producing, if you've spent any time in the System Configuration (like our trusty QA guys) this will be a real time saver.

 

settings-filter.png

 

Changing the layout

I had to refresh my SWT widget layout knowledge a little and found this great page: http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html.  With that excellent refresher I decided I would need a three column GridLayout: a column each for the Edit button, filter label and the filter text widget.  The table would then span all three columns.

 

settings-filter-layout.png

First, simply change the number of columns on the SettingDefinitionComposite:

 

private void setupLayout() {
     final int columns = 3;
     this.setLayout(new GridLayout(columns, false));
}

 

Then add in a horizontal span to the table's LayoutData - this makes it span the three columns we just created.

final int horizontalSpan = 3;
table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, horizontalSpan, 1));

Note: the final variables are to keep Checkstyle quiet about magic numbers.

 

Adding the new widgets

The code below adds the label and the filter Text widget.  Take a close look at the style we are using to create the Text widget with: SWT.SEARCH | SWT.CANCEL.  The SWT.SEARCH style gives us the rounded edges (at least on my Mac) which makes it look like a regular search/filter widget.  The SWT.CANCEL style adds the small cross to the widget.  When clicked it removes the currently entered text.

Label label = formToolkit.createLabel(this, AdminConfigurationMessages.filterLabel + ":"); //$NON-NLS-1$
GridData gridData = new GridData(SWT.END, SWT.CENTER, false, false);
label.setLayoutData(gridData);
Text settingNameFilter = formToolkit.createText(this, "", SWT.SEARCH | SWT.CANCEL); //$NON-NLS-1$
gridData = new GridData(SWT.FILL, SWT.CENTER, false, false);
final int verticalIndent = 10;
gridData.verticalIndent = verticalIndent;
settingNameFilter.setLayoutData(gridData);

 

We want this new addition to be localizable so we need to add AdminConfigurationMessages.filterLabel

public static String filterLabel;

 

And then we provide the English version of that in AdminConfigurationPluginResources.properties

 

filterLabel=Filter

 

Filtering

Now we'll take a look at how we will actually filter down the table's contents.  The code's pretty simple:

/**
 * Filter setting definitions against a specified string.
 */
private class SettingPathFilter extends ViewerFilter {
     private final String filterText;
     public SettingPathFilter(final String filterText) {
          this.filterText = filterText;
     }
     @Override
     public boolean select(final Viewer viewer, final Object parent, final Object element) {
          SettingDefinition definition = (SettingDefinition) element;
          return StringUtils.containsIgnoreCase(definition.getPath(), filterText);
     }
}

We've simply extended the JFace ViewerFilter class and implemented the select method with a case-insensitive check against the setting definition's path.  In the next step we'll create an instance of this class and pass it to the TableViewer that holds the setting definitions.

 

The following page helped me a bit with the ViewerFilter: http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DemonstratesListViewer.htm

 

Hooking it together

The bits are all in place, let's tie them together and get the filtering going when a user types in the text box.  We simply add a ModifyListener to the filter Text widget and when we receive a ModifyEvent we grab the user-entered string, create a new SettingPathFilter and set that on the tableViewer.  That triggers the tableViewer to filter its contents.  Note: I chose to use setFilters, rather than addFilter/removeFilter, to keep the code simple: I don't have to keep track of the filter to remove it afterwards I simply call setFilters again.

 

settingNameFilter.addModifyListener(new ModifyListener() {
     public void modifyText(final ModifyEvent event) {
          final Text source = (Text) event.getSource();
          String filterText = source.getText();
          if (StringUtils.isBlank(filterText)) {
               tableViewer.setFilters(new ViewerFilter [0]);
          } else {
               tableViewer.setFilters(new ViewerFilter [] {new SettingPathFilter(filterText)});
               }
     }
});

 

 

Conclusion

So there you have it, all done, with a few small changes we can find settings without having to visually scan the table.  Where else might this filtering function be useful?  Anyone done any similar customizations they would like to share?

 

The code

The code changes and the attached patch are against the upcoming 6.2 release, but I'm pretty sure they will apply to any 6.1+ version.  Leave a comment if you have any problems applying this and I'll do my best to help you out.

References

http://www.eclipse.org/swt/snippets/ - if you've not taken a look at the SWT snippets then you're missing out.  There's a ton of useful examples of using SWT.

http://wiki.eclipse.org/index.php/JFaceSnippets - just like the SWT snippets, this page contains great snippets about using the JFace ui toolkit.

2 Comments Permalink