aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-11-27 13:55:30 (EST)
committerAlexander Kurtakov2013-12-05 10:42:38 (EST)
commit8c9437b66ca8147a085e1d3c95dac0e074228a35 (patch)
tree28b747294c6299097904743b7662c4bbf04b32bb
parent76c3cfc52c3eee17b87d2969ff1e7c20a2eeaaa3 (diff)
downloadorg.eclipse.linuxtools-8c9437b66ca8147a085e1d3c95dac0e074228a35.zip
org.eclipse.linuxtools-8c9437b66ca8147a085e1d3c95dac0e074228a35.tar.gz
org.eclipse.linuxtools-8c9437b66ca8147a085e1d3c95dac0e074228a35.tar.bz2
RPM: createrepo metadata tags treerefs/changes/99/18999/7
A category tree has been added to the metadata page. It keeps track of the tags a user would like to put in the repository metadata. You can add, edit, or remove tags, and there are only 3 possible categories to add tags to (taken from createrepo options). Currently, tags are being saved via project preferences. The plan is for the execute method to grab all the command line parameters it needs from the project and plugin preferences, preferring project settings over plugin settings if it exists. Change-Id: I0b0d4d4de5860c4cf83ed802d88524a665b518c4 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/18999 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/icons/library_obj.gifbin0 -> 338 bytes
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/icons/templateprop_co.gifbin0 -> 359 bytes
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java4
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java234
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoCategoryModel.java107
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeCategory.java77
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeContentProvider.java86
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeLabelProvider.java50
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoPreferenceConstants.java26
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java15
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java6
13 files changed, 574 insertions, 35 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/library_obj.gif b/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/library_obj.gif
new file mode 100644
index 0000000..cb55e33
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/library_obj.gif
Binary files differ
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/templateprop_co.gif b/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/templateprop_co.gif
new file mode 100644
index 0000000..fdde5fb
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/icons/templateprop_co.gif
Binary files differ
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
index cea875a..4a77328 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/Messages.java
@@ -117,11 +117,15 @@ public final class Messages {
/****/
public static String MetadataPage_sectionInstructionTags;
/****/
+ public static String MetadataPage_labelTags;
+ /****/
public static String MetadataPage_buttonAddTag;
/****/
public static String MetadataPage_buttonEditTag;
/****/
public static String MetadataPage_buttonRemoveTag;
+ /****/
+ public static String MetadataPage_errorSavingPreferences;
// CreaterepoResourceChangeListener
/****/
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
index a9ac166..1d6f106 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/MetadataPage.java
@@ -10,9 +10,24 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.createrepo.form;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoCategoryModel;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeContentProvider;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeLabelProvider;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoPreferenceConstants;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -23,6 +38,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
@@ -31,6 +47,7 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.menus.IMenuService;
+import org.osgi.service.prefs.BackingStoreException;
/**
* This page will allow the user to view/edit some of the repo
@@ -38,19 +55,26 @@ import org.eclipse.ui.menus.IMenuService;
*/
public class MetadataPage extends FormPage {
+ private CreaterepoProject project;
+ private IEclipsePreferences eclipsePreferences;
+
private FormToolkit toolkit;
private ScrolledForm form;
private Text revisionTxt;
+ private Text tagTxt;
private Tree tagsTree;
+ private TreeViewer tagsTreeViewer;
private Composite buttonList;
private static final String MENU_URI = "toolbar:formsToolbar"; //$NON-NLS-1$
- private static final String HEADER_ICON = "/icons/repository_rep.gif"; //$NON-NLS-1$
+ private static final String HEADER_ICON = "/icons/library_obj.gif"; //$NON-NLS-1$
/** Default constructor. */
- public MetadataPage(FormEditor editor) {
+ public MetadataPage(FormEditor editor, CreaterepoProject project) {
super(editor, Messages.MetadataPage_title, Messages.MetadataPage_title);
+ this.project = project;
+ eclipsePreferences = project.getEclipsePreferences();
}
/*
@@ -99,6 +123,10 @@ public class MetadataPage extends FormPage {
sectionClient.setLayout(layout);
revisionTxt = createTextFieldWithLabel(sectionClient, Messages.MetadataPage_labelRevision);
+ String prefRevisionTxt = eclipsePreferences.get(CreaterepoPreferenceConstants.PREF_REVISION, ICreaterepoConstants.EMPTY_STRING);
+ if (!prefRevisionTxt.isEmpty()) {
+ revisionTxt.setText(prefRevisionTxt);
+ }
revSection.setClient(sectionClient);
//---------- REVISION SECTION END
@@ -117,9 +145,51 @@ public class MetadataPage extends FormPage {
layout.marginWidth = 1; layout.marginHeight = 7;
sectionClientTags.setLayout(layout);
- // TODO: create custom tree to handle tags in specific categories (distro, content, repo)
- tagsTree = toolkit.createTree(sectionClientTags, SWT.BORDER | SWT.MULTI | SWT.HORIZONTAL
+ tagTxt = createTextFieldWithLabel(sectionClientTags, Messages.MetadataPage_labelTags);
+ tagTxt.addSelectionListener(new SelectionAdapter() {
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ addTag();
+ }
+ });
+
+ tagsTreeViewer = new TreeViewer(sectionClientTags, SWT.BORDER | SWT.SINGLE | SWT.HORIZONTAL
| SWT.VERTICAL | SWT.LEFT_TO_RIGHT | SWT.SMOOTH);
+ tagsTreeViewer.setContentProvider(new CreaterepoTreeContentProvider());
+ tagsTreeViewer.setLabelProvider(new CreaterepoTreeLabelProvider());
+ CreaterepoCategoryModel test = new CreaterepoCategoryModel(project);
+ tagsTreeViewer.setInput(test);
+ // change the tag text field on change (make editing tag easier)
+ tagsTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (tagsTree.getSelectionCount() == 1) {
+ TreeItem treeItem = tagsTree.getSelection()[0];
+ if (!(treeItem.getData() instanceof CreaterepoTreeCategory)) {
+ String tag = (String) treeItem.getData();
+ tagTxt.setText(tag);
+ } else {
+ tagTxt.setText(ICreaterepoConstants.EMPTY_STRING);
+ }
+ }
+ }
+ });
+ // expand or shrink a category
+ tagsTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) tagsTreeViewer.getSelection();
+ if (selection.getFirstElement() instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) selection.getFirstElement();
+ tagsTreeViewer.setExpandedState(category, !tagsTreeViewer.getExpandedState(category));
+ }
+ }
+ });
+ tagsTree = tagsTreeViewer.getTree();
tagsTree.setLayoutData(expandComposite());
// everything to do with the buttons
@@ -137,17 +207,34 @@ public class MetadataPage extends FormPage {
toolkit).addSelectionListener(new RemoveTagButtonListener());
tagSection.setClient(sectionClientTags);
//---------- TAGS SECTION END
-
+ refreshTree();
managedForm.refresh();
}
/**
+ * Refresh the tree. This includes removing the expand button of a
+ * category if there are no tags placed under it.
+ */
+ private void refreshTree() {
+ // expand categories with no tags under them to remove expand button
+ for (TreeItem treeItem : tagsTree.getItems()) {
+ if (treeItem.getData() instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
+ if (category.getTags().isEmpty()) {
+ tagsTreeViewer.expandToLevel(category, 1);
+ tagsTreeViewer.update(category, null);
+ }
+ }
+ }
+ }
+
+ /**
* Make a GridData that expands to fill both horizontally
* and vertically.
*
* @return The created GridData.
*/
- private static GridData expandComposite() {
+ protected static GridData expandComposite() {
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
@@ -155,6 +242,7 @@ public class MetadataPage extends FormPage {
data.grabExcessVerticalSpace = true;
return data;
}
+
/**
* Create a push style button.
*
@@ -163,7 +251,7 @@ public class MetadataPage extends FormPage {
* @param toolkit The form toolkit used in creating a button.
* @return The button created.
*/
- private Button createPushButton(Composite parent, String buttonText, FormToolkit toolkit) {
+ protected Button createPushButton(Composite parent, String buttonText, FormToolkit toolkit) {
Button button = toolkit.createButton(parent, buttonText, SWT.PUSH | SWT.FLAT
| SWT.CENTER | SWT.LEFT_TO_RIGHT);
button.setFont(parent.getFont());
@@ -180,15 +268,26 @@ public class MetadataPage extends FormPage {
* @return The newly created text field.
*/
protected Text createTextFieldWithLabel(Composite parent, String labelName) {
+ // set up the area in which the label and text will reside
+ Composite areaLabelText = new Composite(parent, SWT.NONE);
GridData layoutData = new GridData();
+ GridLayout gridlayout = new GridLayout(2, false);
+ layoutData.horizontalAlignment = GridData.FILL;
+ layoutData.verticalAlignment = GridData.CENTER;
+ layoutData.horizontalSpan = 2;
+ layoutData.grabExcessHorizontalSpace = true;
+ areaLabelText.setLayoutData(layoutData);
+ areaLabelText.setLayout(gridlayout);
// create the label
- Label respositoryBaseURLLbl = new Label(parent, SWT.NONE);
+ Label respositoryBaseURLLbl = new Label(areaLabelText, SWT.NONE);
respositoryBaseURLLbl.setText(labelName);
layoutData = new GridData();
+ layoutData.widthHint = 100;
layoutData.horizontalAlignment = GridData.BEGINNING;
layoutData.verticalAlignment = GridData.CENTER;
+ respositoryBaseURLLbl.setLayoutData(layoutData);
// create the text field
- Text textField = new Text(parent, SWT.SINGLE);
+ Text textField = new Text(areaLabelText, SWT.SINGLE);
layoutData = new GridData();
layoutData.horizontalIndent = 50;
layoutData.grabExcessHorizontalSpace = true;
@@ -196,12 +295,68 @@ public class MetadataPage extends FormPage {
layoutData.verticalAlignment = GridData.CENTER;
// achieve flat look (don't put SWT.BORDER)
textField.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
- toolkit.paintBordersFor(parent);
textField.setLayoutData(layoutData);
+ toolkit.paintBordersFor(areaLabelText);
return textField;
}
/**
+ * Save the project preferences of some value to a key.
+ *
+ * @param key The preferences key.
+ * @param val The value to save.
+ */
+ protected void savePreferences(String key, String val) {
+ eclipsePreferences.put(key, val);
+ try {
+ eclipsePreferences.flush();
+ refreshTree();
+ } catch (BackingStoreException e) {
+ Activator.logError(Messages.MetadataPage_errorSavingPreferences, e);
+ }
+ }
+
+ /**
+ * Prepare the tags to be saved to the preference. This class gets all the tags
+ * from a category and transforms it into a semicolon-delimited string.
+ *
+ * @param category The category to prepare the tag string for.
+ * @return A semicolon-delimited string of tags taken from the category.
+ */
+ private static String preparePreferenceTag(CreaterepoTreeCategory category) {
+ String preferenceToSave = ICreaterepoConstants.EMPTY_STRING;
+ if (!category.getTags().isEmpty()) {
+ for (String tag : category.getTags()){
+ preferenceToSave = preferenceToSave.concat(tag+ICreaterepoConstants.DELIMITER);
+ }
+ // remove the hanging delimiter
+ preferenceToSave = preferenceToSave.substring(0, preferenceToSave.length()-1);
+ }
+ return preferenceToSave;
+ }
+
+ /**
+ * Method to add the tag from the tag text field to the category in the tree.
+ * Used by the "Add" button and the default operation when ENTER is pressed while
+ * in the tag text field.
+ */
+ protected void addTag() {
+ IStructuredSelection selection = (IStructuredSelection) tagsTreeViewer.getSelection();
+ if (selection.getFirstElement() instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) selection.getFirstElement();
+ String text = tagTxt.getText().trim();
+ if (!text.isEmpty()) {
+ category.addTag(text);
+ tagsTreeViewer.refresh(category, false);
+ tagsTreeViewer.setExpandedState(category, true);
+ tagTxt.setText(ICreaterepoConstants.EMPTY_STRING);
+ String preferenceToSave = preparePreferenceTag(category);
+ savePreferences(category.getName(), preferenceToSave);
+ }
+ }
+ }
+
+ /**
* Handle the add button execution on the Metadata page.
*/
public class AddTagButtonListener extends SelectionAdapter {
@@ -210,14 +365,9 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
+ public void widgetSelected(SelectionEvent e) {
+ addTag();
+ }
}
/**
@@ -229,14 +379,24 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
+ public void widgetSelected(SelectionEvent e) {
+ if (tagsTree.getSelectionCount() == 1) {
+ TreeItem treeItem = tagsTree.getSelection()[0];
+ String newTag = tagTxt.getText().trim();
+ if (!(treeItem.getData() instanceof CreaterepoTreeCategory) && !newTag.isEmpty()) {
+ CreaterepoTreeCategory parent = (CreaterepoTreeCategory) treeItem.getParentItem().getData();
+ String oldTag = (String) treeItem.getData();
+ int oldTagIndex = parent.getTags().indexOf(oldTag);
+ if (parent.getTags().indexOf(newTag) == -1) {
+ parent.getTags().set(oldTagIndex, newTag);
+ tagsTreeViewer.refresh(parent, true);
+ tagsTree.setSelection(treeItem);
+ String preferenceToSave = preparePreferenceTag(parent);
+ savePreferences(parent.getName(), preferenceToSave);
+ }
+ }
+ }
+ }
}
/**
@@ -248,14 +408,20 @@ public class MetadataPage extends FormPage {
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
- public void widgetSelected(SelectionEvent e) { }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {/* not implemented */}
+ public void widgetSelected(SelectionEvent e) {
+ if (tagsTree.getSelectionCount() == 1) {
+ TreeItem treeItem = tagsTree.getSelection()[0];
+ if (!(treeItem.getData() instanceof CreaterepoTreeCategory)) {
+ CreaterepoTreeCategory parent = (CreaterepoTreeCategory) treeItem.getParentItem().getData();
+ String tag = (String) treeItem.getData();
+ parent.removeTag(tag);
+ tagsTreeViewer.refresh(parent, true);
+ tagTxt.setText(ICreaterepoConstants.EMPTY_STRING);
+ String preferenceToSave = preparePreferenceTag(parent);
+ savePreferences(parent.getName(), preferenceToSave);
+ }
+ }
+ }
}
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
index d59bd94..940e42f 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/RepoFormEditor.java
@@ -127,7 +127,7 @@ public class RepoFormEditor extends FormEditor {
*/
void createPage1() {
try {
- FormPage composite = new MetadataPage(this);
+ FormPage composite = new MetadataPage(this, project);
addPage(composite);
} catch (PartInitException e) {
Activator.logError(Messages.RepoFormEditor_errorInitializingForm, e);
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
index b6db13d..70c14e1 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/messages.properties
@@ -74,9 +74,11 @@ MetadataPage_sectionInstructionRevision=Update the repository revision number. C
MetadataPage_labelRevision=&Revision:
MetadataPage_sectionTitleTags=Tags
MetadataPage_sectionInstructionTags=Add or remove as many tags per category as needed. Changes take effect after execution.
+MetadataPage_labelTags=&Tag:
MetadataPage_buttonAddTag=&Add
MetadataPage_buttonEditTag=&Edit
MetadataPage_buttonRemoveTag=&Remove
+MetadataPage_errorSavingPreferences=Error occured saving the data to preferences.
# CreaterepoResourceChangeListener
CreaterepoResourceChangeListener_errorGettingResource=Error trying to get the resource from the editor.
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoCategoryModel.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoCategoryModel.java
new file mode 100644
index 0000000..64522d1
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoCategoryModel.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.tree;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoPreferenceConstants;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+
+/**
+ * The category and tags (if any) of the metadata tree.
+ */
+public class CreaterepoCategoryModel {
+
+ private IEclipsePreferences projectPreferences;
+
+ public CreaterepoCategoryModel(CreaterepoProject project) {
+ if (project != null) {
+ projectPreferences = project.getEclipsePreferences();
+ }
+ }
+
+ /**
+ * The only categories acceptable by createrepo. The categories will be populated with
+ * tags found from the project preferences (if any).
+ *
+ * @return Initial categories and saved tags (if any).
+ */
+ public List<CreaterepoTreeCategory> getCategories() {
+ List<CreaterepoTreeCategory> model = new ArrayList<CreaterepoTreeCategory>();
+ CreaterepoTreeCategory distroCat = new CreaterepoTreeCategory(
+ CreaterepoPreferenceConstants.PREF_DISTRO_TAG);
+ distroCat.addAllTags(getDistroTags());
+ CreaterepoTreeCategory contentCat = new CreaterepoTreeCategory(
+ CreaterepoPreferenceConstants.PREF_CONTENT_TAG);
+ contentCat.addAllTags(getContentTags());
+ CreaterepoTreeCategory repoCat = new CreaterepoTreeCategory(
+ CreaterepoPreferenceConstants.PREF_REPO_TAG);
+ repoCat.addAllTags(getRepoTags());
+ model.add(distroCat);
+ model.add(contentCat);
+ model.add(repoCat);
+ return model;
+ }
+
+ /**
+ * Get the distro tags from the project preferences.
+ *
+ * @return The prefered distro tags or empty if no preferences stored.
+ */
+ private List<String> getDistroTags() {
+ if (projectPreferences != null) {
+ String tagPref = projectPreferences.get(CreaterepoPreferenceConstants.PREF_DISTRO_TAG,
+ ICreaterepoConstants.EMPTY_STRING);
+ if (!tagPref.isEmpty()) {
+ return Arrays.asList(tagPref.split(ICreaterepoConstants.DELIMITER));
+ }
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * Get the content tags from the project preferences.
+ *
+ * @return The prefered content tags or empty if no preferences stored.
+ */
+ private List<String> getContentTags() {
+ if (projectPreferences != null) {
+ String tagPref = projectPreferences.get(CreaterepoPreferenceConstants.PREF_CONTENT_TAG,
+ ICreaterepoConstants.EMPTY_STRING);
+ if (!tagPref.isEmpty()) {
+ return Arrays.asList(tagPref.split(ICreaterepoConstants.DELIMITER));
+ }
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * Get the repo tags from the project preferences.
+ *
+ * @return The prefered repo tags or empty if no preferences stored.
+ */
+ private List<String> getRepoTags() {
+ if (projectPreferences != null) {
+ String tagPref = projectPreferences.get(CreaterepoPreferenceConstants.PREF_REPO_TAG,
+ ICreaterepoConstants.EMPTY_STRING);
+ if (!tagPref.isEmpty()) {
+ return Arrays.asList(tagPref.split(ICreaterepoConstants.DELIMITER));
+ }
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeCategory.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeCategory.java
new file mode 100644
index 0000000..69603df
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeCategory.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.tree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Categories and tags used by the tree in the metadata page.
+ */
+public class CreaterepoTreeCategory {
+
+ private String name;
+ private List<String> tags = new ArrayList<String>();
+
+ /**
+ * Default constructor to initialize name of the
+ * category at instantiation.
+ *
+ * @param name Name of category.
+ */
+ public CreaterepoTreeCategory(String name) {
+ if (name != null && !name.isEmpty()) {
+ this.name = name;
+ }
+ }
+
+ /**
+ * @return The category name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param tag The tag to remove from the category.
+ */
+ public void removeTag(String tag) {
+ if (tags.contains(tag)) {
+ tags.remove(tag);
+ }
+ }
+
+ /**
+ * @param tag A unique tag to add to the category.
+ */
+ public void addTag(String tag) {
+ if (!tags.contains(tag)) {
+ tags.add(tag);
+ }
+ }
+
+ /**
+ * @param tags A list of tags to add to the category.
+ */
+ public void addAllTags(List<String> tags) {
+ for (String tag : tags) {
+ addTag(tag);
+ }
+ }
+
+ /**
+ * @return The tags in the category.
+ */
+ public List<String> getTags() {
+ return tags;
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeContentProvider.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeContentProvider.java
new file mode 100644
index 0000000..e3f413d
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeContentProvider.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.tree;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * The content provider for the category tree in the metadata form page.
+ */
+public class CreaterepoTreeContentProvider implements ITreeContentProvider {
+
+ private CreaterepoCategoryModel model;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {/* not implemented */}
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof CreaterepoCategoryModel) {
+ model = (CreaterepoCategoryModel) newInput;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+ return model.getCategories().toArray();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) parentElement;
+ return category.getTags().toArray();
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) element;
+ // category has children if ! empty
+ return !category.getTags().isEmpty();
+ }
+ return false;
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeLabelProvider.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeLabelProvider.java
new file mode 100644
index 0000000..f97156c
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/CreaterepoTreeLabelProvider.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.tree;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Provide the labels and images.
+ */
+public class CreaterepoTreeLabelProvider extends LabelProvider {
+
+ private static final String CATEGORY_IMAGE = "icons/library_obj.gif"; //$NON-NLS-1$
+ private static final String TAG_IMAGE = "icons/templateprop_co.gif"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ if (element instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) element;
+ return category.getName();
+ }
+ return element.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof CreaterepoTreeCategory) {
+ return Activator.getImageDescriptor(CATEGORY_IMAGE).createImage();
+ }
+ return Activator.getImageDescriptor(TAG_IMAGE).createImage();
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoPreferenceConstants.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoPreferenceConstants.java
new file mode 100644
index 0000000..a0cbcb0
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoPreferenceConstants.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.rpm.createrepo;
+
+/**
+ * Constants used for createrepo preferences.
+ */
+public final class CreaterepoPreferenceConstants {
+
+ /*
+ * Preference Keys.
+ */
+ /****/ public static final String PREF_DISTRO_TAG = "distro"; //$NON-NLS-1$
+ /****/ public static final String PREF_CONTENT_TAG = "content"; //$NON-NLS-1$
+ /****/ public static final String PREF_REPO_TAG = "repo"; //$NON-NLS-1$
+ /****/ public static final String PREF_REVISION = "revision"; //$NON-NLS-1$
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
index 40f922d..0fbfb5e 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/CreaterepoProject.java
@@ -20,12 +20,15 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.osgi.framework.FrameworkUtil;
@@ -35,6 +38,8 @@ import org.osgi.framework.FrameworkUtil;
*/
public class CreaterepoProject {
+ private IEclipsePreferences projectPreferences;
+
private IProject project;
private IFolder content;
private IFile repoFile;
@@ -61,6 +66,7 @@ public class CreaterepoProject {
this.project = project;
this.repoFile = repoFile;
monitor = new NullProgressMonitor();
+ projectPreferences = new ProjectScope(project.getProject()).getNode(Activator.PLUGIN_ID);
intitialize();
// if something is deleted from the project while outside of eclipse,
// the tree/preferences will be updated accordingly after refreshing
@@ -171,4 +177,13 @@ public class CreaterepoProject {
return rpms;
}
+ /**
+ * Get the eclipse preferences of this project.
+ *
+ * @return The eclipse preferences for the project.
+ */
+ public IEclipsePreferences getEclipsePreferences() {
+ return projectPreferences;
+ }
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
index 48d47da..1e1f8fb 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo/src/org/eclipse/linuxtools/rpm/createrepo/ICreaterepoConstants.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.rpm.createrepo;
+
/**
* Common constants used in createrepo.
*/
@@ -28,6 +29,11 @@ public interface ICreaterepoConstants {
String REPO_FILE_EXTENSION = "repo"; //$NON-NLS-1$
/**
+ * The delimiter of preferences.
+ */
+ String DELIMITER = ";"; //$NON-NLS-1$
+
+ /**
* The file extension of RPM files.
*/
String RPM_FILE_EXTENSION = "rpm"; //$NON-NLS-1$