Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DinisCruz/8023990 to your computer and use it in GitHub Desktop.

Select an option

Save DinisCruz/8023990 to your computer and use it in GitHub Desktop.
Dynamically programming Eclipse preferences page
import tm.eclipse.ui.PluginPreferences.*;
def mainPreferences = new MainPreferences();
def viewId = "test login preferences";
eclipseUI.add_View(viewId).close()
def view = eclipseUI.add_View(viewId);
mainPreferences.control = view.composite;
mainPreferences.createContents(view.composite)
return "done";
public void createFieldEditors()
{
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SERVER , "TeamMentor &Server:" , getFieldEditorParent()));
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SESSION_ID , "TeamMentor &SessionId:" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_OPEN_ARTICLE_NEW_WINDOW , "&Open TeamMentor article in new window" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_LOAD_PLUGINS , "&Load Plugins on Startup" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_ADVANCED_MODE , "&Show Advanced Mode Features" , getFieldEditorParent()));
Composite parent= getFieldEditorParent();
Label label1 = new Label(parent,SWT.BORDER);
label1.setText("label #1");
Text text1 = new Text(parent,SWT.BORDER);
text1.setText("text 1");
Label label2= new Label(parent,SWT.BORDER);
label2.setText("label #2");
Text text2 = new Text(parent,SWT.BORDER);
text2.setText("text 2");
}
public void createFieldEditors()
{
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SERVER , "TeamMentor &Server:" , getFieldEditorParent()));
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SESSION_ID , "TeamMentor &SessionId:" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_OPEN_ARTICLE_NEW_WINDOW , "&Open TeamMentor article in new window" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_LOAD_PLUGINS , "&Load Plugins on Startup" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_ADVANCED_MODE , "&Show Advanced Mode Features" , getFieldEditorParent()));
Composite parent= getFieldEditorParent();
Group group = new Group(parent, SWT.BORDER);
ObjectBrowser.inspect(group);
....
public void createFieldEditors()
{
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SERVER , "TeamMentor &Server:" , getFieldEditorParent()));
addField(new StringFieldEditor (PreferenceInitializer.P_TEAMMENTOR_SESSION_ID , "TeamMentor &SessionId:" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_OPEN_ARTICLE_NEW_WINDOW , "&Open TeamMentor article in new window" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_LOAD_PLUGINS , "&Load Plugins on Startup" , getFieldEditorParent()));
addField(new BooleanFieldEditor(PreferenceInitializer.P_TEAMMENTOR_ADVANCED_MODE , "&Show Advanced Mode Features" , getFieldEditorParent()));
Composite parent= getFieldEditorParent();
new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL)
.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
String groupTitle = "To get a token You can use the form below to login into the current TeamMentor server (set above)";
new Label(parent,SWT.BORDER).setText(groupTitle);
//Group group = new Group(parent, SWT.BORDER);
Group group = new Group(parent, SWT.NONE);
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
gridData.verticalAlignment = 20;
group.setLayoutData(gridData);
group.setLayout(new GridLayout(2, false));
new Label(group,SWT.BORDER).setText("User name:");
Text username_Text = new Text(group,SWT.BORDER);
username_Text.setText("....");
username_Text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(group,SWT.BORDER).setText("Password");
Text password_Text = new Text(group,SWT.BORDER);
password_Text.setText("***");
password_Text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button login_Button = new Button(group, SWT.NONE);
login_Button.setText("Get Token");
logMessage(parent.getLayout().toString());
}
public void logMessage(String message)
{
String consoleName = "TeamMentor Scripts";
Console console = Startup.eclipseApi.console;
console.new_MessageConsole(consoleName);
//console.get(consoleName).clearConsole(); // use to clear
console.write(consoleName, message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment