Preferences in the Eclipse Workbench UI Present by Kun-Tse Wu.

Slides:



Advertisements
Similar presentations
Java Card Technology Ch04: Java Card Object
Advertisements

Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Lecture 15: I/O and Parsing
MiniDraw Testing COMP 102 # T1
1 org.eclips.ui package org.eclipse.ui. 2 Package org.eclipse.ui Description l Application programming interfaces for interaction with any extension of.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Preferences in Eclipse 3.0 Present by Kun-Tse Wu.
1 org.eclipse.ui.texteditor-api l Provides a framework for text editors obeying to the desktop rules. org.eclipse.ui.texteditor.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
CS 206 Introduction to Computer Science II 01 / 23 / 2009 Instructor: Michael Eckmann.
Preferences. 2 Persistent storage Information is persistent if it is kept between one invocation of a program and the next Many programs keep user preferences.
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
UNIT-V The MVC architecture and Struts Framework.
Data Storage: Part 1 (Preferences)
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Deutsches Elektronen-Synchrotron DESY Helmholtz Association of German Research Centres Hamburg, Germany The European X-Ray Laser Project.
Writing Widgets & Custom Script API for BOY Xihui Chen
ECE 452 / CS 446 / SE464 Design Patterns: Part 2 - Answers A Tutorial By Peter Kim Partially based on the tutorial by Michał Antkiewicz.
Introduction to Eclipse Plug-in Development. Who am I? Scott Kellicker Java, C++, JNI, Eclipse.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Ontology Engineering and Plugin Development with the NeOn Toolkit Plug-in Development for the NeOn Toolkit June 1st, 2008 Michael Erdmann, Peter Haase,
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Welcome To Eclipse. Basic Concepts Workspace – directory where your projects are stored –Projects grouping of related works –Resources generic term to.
GWT Development with Activities and Places
Present by Wu Kun-Tse Simplifying Preference Pages with Field Editors.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
A brief introduction to doxygen. What does a compiler do?  A compiler ignores comments and processes the code.  What does doxygen do? –It ignores the.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Introduction to HTML Simple facts yet crucial to beginning of study in fundamentals of web page design!
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Preferences. 2 Persistent storage Information is persistent if it is kept between one invocation of a program and the next Many programs keep user preferences.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
3 Introduction to Classes and Objects.
Delegates and Events 14: Delegates and Events
COSC-4840 Software Engineering
A brief introduction to doxygen
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Eclipse Plug-in Development
CS 350 – Software Design Singleton – Chapter 21
Constructors, GUI’s(Using Swing) and ActionListner
Preferences.
Preferences.
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Preferences.
Preferences.
Preferences.
Preference Activity class
Plug-In Architecture Pattern
Presentation transcript:

Preferences in the Eclipse Workbench UI Present by Kun-Tse Wu

Outline Introduction When to Use a Preference The Preference Store and the Plug-in Defining Preference Pages in plugin.xml The Color Preference Page The Bad Words Preference Page Propagating Values With IPropertyChangeListener Importing and Exporting Preference Settings Conclusions

Introduction This article will discuss what type of data should be stored as a preference and will show how to develop and register a user interface to allow the user to set these preferences as well as how to store them independent of the workbench by use of the import and export functions.

When to Use a Preference A preference is data that is persisted between workspace sessions to allow the user to keep the state of a plug-in consistent between Eclipse sessions. Preferences are not intended to reference any resource currently defined in the workspace and instead should be used for editors, views or other objects that perform operations on a resource. Data persisted on a resource instance is better suited to be a property.

The Preference Store and the Plug-in We define a plug-in and use its preference store for our preferences. Each preference value is looked up using a given key. The constructor will create a singleton to allow easy access to the plug-in instance in the workbench. Use initializeDefaultPreferences(IPreferenceStore) method to initialize a preference store with default preference values for this plug-in.

The Preference Store and the Plug-in (cont.) public class BadWordCheckerPlugin extends AbstractUIPlugin { // The identifiers for the preferences public static final String BAD_WORDS_PREFERENCE = "badwords"; public static final String HIGHLIGHT_PREFERENCE = "highlight"; // The constructor. public BadWordCheckerPlugin(IPluginDescriptor descriptor) { super(descriptor); plugin = this; } // Initializes a preference store with default preference values for this plug-in. protected void initializeDefaultPreferences(IPreferenceStore store) { store.setDefault(BAD_WORDS_PREFERENCE, DEFAULT_BAD_WORDS); Color color= Display.getDefault().getSystemColor(DEFAULT_HIGHLIGHT); PreferenceConverter.setDefault(store, HIGHLIGHT_PREFERENCE, color.getRGB()); }

Defining Preference Pages in plugin.xml Plug-in developers should add their preference pages to preferences dialog (Window->Preferences) by using the plugin.xml. sets the name of the preference page for use in the list of pages in the preference dialog. specifies the class to be instantiated for creating the preference page. In the second definition there is a category tag which is used to make one page the child of another in the list in the preferences dialog.

Defining Preference Pages in plugin.xml (cont.) <page id="BadWordsPreferencePage" name="Bad Words" class="org.eclipse.ui.articles.badwordchecker.BadWordsPreferencePage"> <page id="BadWordsColorPreferencePage" name="Colors" class="org.eclipse.ui.articles.badwordchecker.BadWordsColorPreferencePage" category="BadWordsPreferencePage">

Defining Preference Pages in plugin.xml (cont.)

The Color Preference Page The color preference page is an example of a simple page that uses a single JFace field editor to manage its values. The class PreferencePage which implements most of the necessary API for a preference page.

The Color Preference Page (cont.) class BadWordsColorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public void init(IWorkbench workbench) { //Initialize the preference store we wish to use setPreferenceStore(BadWordCheckerPlugin.getDefault().getPreferenceStore()); } protected void performDefaults() { colorEditor.loadDefault(); } // Save the color preference to the preference store. public boolean performOk() { colorEditor.store(); return super.performOk(); }

The Color Preference Page (cont.)

The Bad Words Preference Page For this example we are going to add a bad words preference which is an array of Strings. As the PreferenceConverter does not have API for conversion of arrays of Strings we will implement it ourselves. The String array is stored in the preference store as a single string separated by semicolons.

The Bad Words Preference Page (cont.) // Converts PREFERENCE_DELIMITER delimited String to a String array. private String[] convert(String preferenceValue) { StringTokenizer tokenizer = new StringTokenizer(preferenceValue, PREFERENCE_DELIMITER); int tokenCount = tokenizer.countTokens(); String[] elements = new String[tokenCount]; for (int i = 0; i < tokenCount; i++) { elements[i] = tokenizer.nextToken(); } return elements; } // Sets the bad words preference. public void setBadWordsPreference(String[] elements) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < elements.length; i++) { buffer.append(elements[i]); buffer.append(PREFERENCE_DELIMITER); } getPreferenceStore().setValue(BAD_WORDS_PREFERENCE, buffer.toString()); }

The Bad Words Preference Page (cont.)

Propagation Values With IPropertyChangeListener IPropertyChangeListener is a class that is used to add a listener to an IPropertyStore so that the listener is informed whenever a change is made. This typically happens when the user hits OK or Apply in a preference dialog, or when a previously saved preference setting is imported.

Propagation Values With IPropertyChangeListener (cont.) new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(BadWordCheckerPlugin.HIGHLIGHT_PREFERENCE)) { //Update the colors by clearing the current color, //updating the view and then disposing the old color. Color oldForeground = foreground; foreground = null; setBadWordHighlights(text.getText()); oldForeground.dispose(); } if (event.getProperty().equals(BadWordCheckerPlugin.BAD_WORDS_PREFERENCE)) { //Only update the text if only the words have changed setBadWordHighlights(text.getText()); } };

Propagation Values With IPropertyChangeListener (cont.) public void init(IViewSite site) throws PartInitException { super.init(site); site.getPage().addSelectionListener(...); BadWordCheckerPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(preferenceListener); } public void dispose() { getSite().getPage().removeSelectionListener(...); BadWordCheckerPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(preferenceListener); if (foreground != null) foreground.dispose(); super.dispose(); }

Importing and Exporting Preference Settings As of Eclipse 2.0 there is now a facility to import and export your preferences so that you can reload them when you get a new workspace. The currently set preferences are stored in a.epf file that you specify when you export.

Conclusions In this article we have demonstrated how to use the preferences store and preferences pages provided by Eclipse to allow a plug-in to maintain and update preferences between Eclipse sessions and to import and export them using the preference dialog. By use of the preference store in conjunction with the preferences dialog and provided field editors a plug-in developer can quickly put together a user interface for managing preferences.

Reference From: Preferences/preferences.htmhttp:// Preferences/preferences.htm Source Code: preferences.zippreferences.zip