Version and Build Number in About Dialog [message #899266] |
Tue, 31 July 2012 05:17  |
Eclipse User |
|
|
|
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 #900389 is a reply to message #899266] |
Mon, 06 August 2012 16:05   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.05081 seconds