Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Version and Build Number in About Dialog
Version and Build Number in About Dialog [message #899266] Tue, 31 July 2012 05:17 Go to next message
J R is currently offline J R
Messages: 3
Registered: July 2012
Junior Member
Hi,

What is a proper way to include product version and build number in about dialog?

Something like 1.0.0.201207311215 (version and date) would be enough.

I'm thinking about getting plugin version (as it has version and date as qualifier) and putting it in about dialog using dynamic product definition but maybe there is a better "standard" way to do it?

Can you point me the right direction?
Re: Version and Build Number in About Dialog [message #900261 is a reply to message #899266] Mon, 06 August 2012 04:48 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
On 31.07.2012 11:17, J R wrote:
> Hi,
>
> What is a proper way to include product version and build number in
> about dialog?
E.g. take a look at the Eclipse SDK about dialog. There we have:

Version: 3.8.0
Build id: M20120802-1000

Dani
Re: Version and Build Number in About Dialog [message #900389 is a reply to message #899266] Mon, 06 August 2012 16:05 Go to previous messageGo to next message
Joaquin Morcate is currently offline Joaquin Morcate
Messages: 49
Registered: March 2010
Member
Hi JR
I have added a command that displays an About dialog:

package org.myproject;

import java.util.Dictionary;

import nato.namsa.sssb.console.ConsoleActivator;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;

public class AboutHandler extends AbstractHandler implements IHandler {

	// -------------------------------------------------------------------------
	// Constants
	// -------------------------------------------------------------------------
	/**
	 * The company logo to be displayed on the left of the dialog.
	 */
	private static final Image DIALOG_IMAGE = AbstractUIPlugin
			.imageDescriptorFromPlugin(ConsoleActivator.PLUGIN_ID,
					"icons/logo.gif").createImage();
	/**
	 * The string displayed on the bar of the dialog.
	 */
	private static final String DIALOG_TITLE = "About My Project";
	/**
	 * The type of the dialog. Not used in our case.
	 */
	private static final int NONE = 0;
	/**
	 * Label for the only button on the dialogue.
	 */
	private static final String[] DIALOG_BUTTONS_LABELS = new String[] { IDialogConstants.OK_LABEL };
	/**
	 * The index for the selected button by default.
	 */
	private static final int DEFAULT_INDEX = 0;
	/**
	 * First line displayed in the text dialogue area.
	 */
	private static final String DIALOG_MESSAGE_TITLE = "\n\n\nMy Project";
	/**
	 * The copyright line
	 */
	private static final String COPYRIGHT_LINE = "(c) Copyright Matrix (2011-2012)";

	// -------------------------------------------------------------------------
	// Inner classes
	// -------------------------------------------------------------------------
	/**
	 * Custom dialogue displaying information about the console version and
	 * build.
	 * 
	 * 
	 */
	class AboutDialog extends MessageDialog {

		// ---------------------------------------------------------------------
		// Constructor
		// ---------------------------------------------------------------------
		/**
		 * Constructor for the custom dialog.
		 * 
		 * @param parentShell
		 *            the shell containing the dialog.
		 * @param dialogTitle
		 *            title displayed in bar of the dialog.
		 * @param dialogTitleImage
		 *            image to display in the bar of the dialogue. None is used.
		 * @param dialogMessage
		 *            The message to be displayed in the dialogue area. the
		 *            version and build numbers plus the copyright notice.
		 * @param dialogImageType
		 *            no used.
		 * @param dialogButtonLabels
		 *            only the OK button is displayed.
		 * @param defaultIndex
		 *            only one button is used on this dialog so it must be 0.
		 */
		public AboutDialog(Shell parentShell, String dialogTitle,
				Image dialogTitleImage, String dialogMessage,
				int dialogImageType, String[] dialogButtonLabels,
				int defaultIndex) {
			super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
					dialogImageType, dialogButtonLabels, defaultIndex);

		}

		// ---------------------------------------------------------------------
		// MessageDialog implementation.
		// ---------------------------------------------------------------------
		/**
		 * Overridden to return the company logo.
		 * 
		 * @return NSPA logo.
		 */
		@Override
		public Image getImage() {
			return DIALOG_IMAGE;
		}

	}

	// -------------------------------------------------------------------------
	// AbstractHandler implementation
	// -------------------------------------------------------------------------
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		Shell parentShell = HandlerUtil.getActiveShell(event);

		String dialogMessage = getDialogMessage();
		AboutDialog dialog = new AboutDialog(parentShell, DIALOG_TITLE,
				DIALOG_IMAGE, dialogMessage, NONE, DIALOG_BUTTONS_LABELS,
				DEFAULT_INDEX);

		dialog.open();
		return null;
	}

	// -------------------------------------------------------------------------
	// Private Methods
	// -------------------------------------------------------------------------
	/**
	 * Computes the line to be displayed in the text area. This label contains
	 * the number of the product, the version, the build and a copyright notice.
	 * The text if formatted using '\n'.
	 * 
	 * @return the text in the dialog.
	 */
	private String getDialogMessage() {

		Bundle bundle = Platform.getBundle(ConsoleActivator.PLUGIN_ID);
		Dictionary<?, ?> dictionary = bundle.getHeaders();

		String versionLine = getVersionLine((String) dictionary
				.get("Bundle-version"));
		String buildLine = getBuildLine((String) dictionary
				.get("Bundle-version"));
		return DIALOG_MESSAGE_TITLE + "\n\n\n" + versionLine + "\n" + buildLine
				+ "\n\n" + COPYRIGHT_LINE;
	}

	/**
	 * Extract the version part of the bundle version.
	 * 
	 * @param bundleVersion
	 *            the version of the bundle in the format v.m.n.qualifier
	 * @return the version part, i.e. "v.m.n"
	 */
	private String getVersionLine(String bundleVersion) {
		int index = bundleVersion.lastIndexOf('.');

		return "Version: " + bundleVersion.substring(0, index);
	}

	/**
	 * Extract the qualifier part of the bundle version. This has been replaced
	 * in the build by the time stamp in the format yyyymmdd.
	 * 
	 * @param bundleVersion
	 *            the version of the bundle in the format v.m.n.qualifier
	 * @return the version part, i.e. "qualifier"
	 */
	private String getBuildLine(String bundleVersion) {
		int index = bundleVersion.lastIndexOf('.');

		return "Build: " + bundleVersion.substring(index + 1);
	}
}


And that's all.

Joaquin
Re: Version and Build Number in About Dialog [message #1059703 is a reply to message #900389] Tue, 21 May 2013 05:42 Go to previous message
J R is currently offline J R
Messages: 3
Registered: July 2012
Junior Member
Thanks Joaquin. I'll use your solution Smile
Previous Topic:RCP App Logging
Next Topic:Eclipse RCP 3.x - Updating IStatusLineManager of Workbench
Goto Forum:
  


Current Time: Mon Jul 28 22:47:55 EDT 2014

Powered by FUDForum. Page generated in 0.01595 seconds