summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorOlav Lenz2012-11-15 09:29:36 (EST)
committer Olav Lenz2012-11-23 09:11:55 (EST)
commitdde1f04264f728b6aa27b9216ffa7bfe930ae67d (patch)
treef0fac5b130af63e6cc609c5888a9598b76b746c8
parent709840764490776d9ede277a41c705357ad72e17 (diff)
downloadorg.eclipse.recommenders-dde1f04264f728b6aa27b9216ffa7bfe930ae67d.zip
org.eclipse.recommenders-dde1f04264f728b6aa27b9216ffa7bfe930ae67d.tar.gz
org.eclipse.recommenders-dde1f04264f728b6aa27b9216ffa7bfe930ae67d.tar.bz2
[prefs] moved model repository preferences to new subcategory "Model"refs/changes/11/8811/3
-rw-r--r--plugins/org.eclipse.recommenders.rcp/plugin.xml11
-rw-r--r--plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/ModelsPreferencePage.java116
-rw-r--r--plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/PreferencePage.java59
-rw-r--r--plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/RecommendersPreferencePage.java32
4 files changed, 157 insertions, 61 deletions
diff --git a/plugins/org.eclipse.recommenders.rcp/plugin.xml b/plugins/org.eclipse.recommenders.rcp/plugin.xml
index 5aeaae1..698ed2c 100644
--- a/plugins/org.eclipse.recommenders.rcp/plugin.xml
+++ b/plugins/org.eclipse.recommenders.rcp/plugin.xml
@@ -9,6 +9,7 @@
Contributors:
Marcel Bruch - Configuration.
+ Patrick Gottschaemmer, Olav Lenz - add model preference page
-->
<?eclipse version="3.4"?>
@@ -29,15 +30,21 @@
<extension
point="org.eclipse.ui.preferencePages">
<page
- class="org.eclipse.recommenders.internal.rcp.ui.PreferencePage"
+ class="org.eclipse.recommenders.internal.rcp.ui.RecommendersPreferencePage"
id="org.eclipse.recommenders.rcp.category.preferences"
name="Code Recommenders">
</page>
+ <page
+ category="org.eclipse.recommenders.rcp.category.preferences"
+ class="org.eclipse.recommenders.internal.rcp.ui.ModelsPreferencePage"
+ id="org.eclipse.recommenders.rcp.modelpreferences"
+ name="Models">
+ </page>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.recommenders.internal.rcp.ui.PreferenceInitializer">
</initializer>
- </extension>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/ModelsPreferencePage.java b/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/ModelsPreferencePage.java
new file mode 100644
index 0000000..065ef7e
--- /dev/null
+++ b/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/ModelsPreferencePage.java
@@ -0,0 +1,116 @@
+/**
+ * Copyright (c) 2010, 2012 Darmstadt University of Technology.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Gottschaemmer, Olav Lenz - initial API and implementation.
+ */
+package org.eclipse.recommenders.internal.rcp.ui;
+
+import static org.eclipse.recommenders.rcp.RecommendersPlugin.P_REPOSITORY_ENABLE_AUTO_DOWNLOAD;
+import static org.eclipse.recommenders.rcp.RecommendersPlugin.P_REPOSITORY_URL;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.StringButtonFieldEditor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.window.Window;
+import org.eclipse.recommenders.internal.rcp.repo.ClearModelRepositoryJob;
+import org.eclipse.recommenders.rcp.RecommendersPlugin;
+import org.eclipse.recommenders.rcp.repo.ModelRepositoryService;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class ModelsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ public ModelsPreferencePage() {
+ super(GRID);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(RecommendersPlugin.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ createRemoteRepositorySection();
+
+ Button clearCaches = new Button(getFieldEditorParent(), SWT.PUSH);
+ clearCaches.setText("Clear Caches");
+ GridData data = new GridData(SWT.END, SWT.CENTER, false, false);
+ data.horizontalSpan = 3;
+ clearCaches.setLayoutData(data);
+ clearCaches.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ new ClearModelRepositoryJob(ModelRepositoryService.getRepository()).schedule();
+ }
+ });
+ }
+
+ private void createRemoteRepositorySection() {
+ GridData layoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false);
+ layoutData.horizontalSpan = 3;
+
+ Label headline = new Label(getFieldEditorParent(), SWT.LEFT);
+ headline.setText("Model Repository");
+ headline.setLayoutData(layoutData);
+ headline.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
+
+ Label description = new Label(getFieldEditorParent(), SWT.LEFT);
+ description.setText("All models used by Code Recommenders will be downloaded from this repository.");
+ description.setLayoutData(layoutData);
+
+ StringButtonFieldEditor modelRepoFieldEditor = new StringButtonFieldEditor(P_REPOSITORY_URL, "URI:",
+ getFieldEditorParent()) {
+ @Override
+ protected String changePressed() {
+ InputDialog inputDialog = new InputDialog(getShell(), "Model Repository URI",
+ "Please insert an URI for the Model Repository:", oldValue, new IInputValidator() {
+
+ @Override
+ public String isValid(String newText) {
+ if (isValidRepoURI(newText)) {
+ return null;
+ } else {
+ return "Invalid URI";
+ }
+ }
+ });
+ if (inputDialog.open() == Window.OK) {
+ return inputDialog.getValue();
+ }
+ return oldValue;
+ }
+ };
+ modelRepoFieldEditor.getTextControl(getFieldEditorParent()).setEnabled(false);
+ addField(modelRepoFieldEditor);
+
+ addField(new BooleanFieldEditor(P_REPOSITORY_ENABLE_AUTO_DOWNLOAD, "Enable auto-download.",
+ getFieldEditorParent()));
+ }
+
+ private boolean isValidRepoURI(String uri) {
+ try {
+ new URI(uri);
+ } catch (URISyntaxException e) {
+ return false;
+ }
+ return true;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/PreferencePage.java b/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/PreferencePage.java
deleted file mode 100644
index 486371f..0000000
--- a/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/PreferencePage.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (c) 2010 Darmstadt University of Technology.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Marcel Bruch - initial API and implementation.
- */
-package org.eclipse.recommenders.internal.rcp.ui;
-
-import static org.eclipse.recommenders.rcp.RecommendersPlugin.P_REPOSITORY_ENABLE_AUTO_DOWNLOAD;
-import static org.eclipse.recommenders.rcp.RecommendersPlugin.P_REPOSITORY_URL;
-
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.StringFieldEditor;
-import org.eclipse.recommenders.internal.rcp.repo.ClearModelRepositoryJob;
-import org.eclipse.recommenders.rcp.RecommendersPlugin;
-import org.eclipse.recommenders.rcp.repo.ModelRepositoryService;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- public PreferencePage() {
- super(GRID);
- setPreferenceStore(RecommendersPlugin.getDefault().getPreferenceStore());
- setDescription("Model Repository Preferences. All models used by Code Recommenders will be pulled from this repository.");
- }
-
- @Override
- public void createFieldEditors() {
- addField(new StringFieldEditor(P_REPOSITORY_URL, "Model Repository:", getFieldEditorParent()));
- addField(new BooleanFieldEditor(P_REPOSITORY_ENABLE_AUTO_DOWNLOAD, "Enable auto-download.",
- getFieldEditorParent()));
-
- Button clean = new Button(getFieldEditorParent(), SWT.PUSH);
- clean.setText("Clear Caches");
- GridData data = new GridData(SWT.END, SWT.CENTER, false, false);
- data.horizontalSpan = 2;
- clean.setLayoutData(data);
- clean.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- new ClearModelRepositoryJob(ModelRepositoryService.getRepository()).schedule();
- }
- });
- }
-
- @Override
- public void init(final IWorkbench workbench) {
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/RecommendersPreferencePage.java b/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/RecommendersPreferencePage.java
new file mode 100644
index 0000000..7fd8cf6
--- /dev/null
+++ b/plugins/org.eclipse.recommenders.rcp/src/org/eclipse/recommenders/internal/rcp/ui/RecommendersPreferencePage.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2010 Darmstadt University of Technology.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marcel Bruch - initial API and implementation.
+ */
+package org.eclipse.recommenders.internal.rcp.ui;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class RecommendersPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ @Override
+ public void init(final IWorkbench workbench) {
+ // unused
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ noDefaultAndApplyButton();
+ return new Composite(parent, SWT.NONE);
+ }
+} \ No newline at end of file