Search in sources :

Example 1 with CreaterepoTreeCategory

use of org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory in project linuxtools by eclipse.

the class CreaterepoTreeCategoryTest method testCreaterepoTreeCategory.

/**
 * Test the tree category to make sure it initializes and stores tags properly.
 * Tags must be unique, so the category should not add tags that already exist
 * within the category.
 */
@Test
public void testCreaterepoTreeCategory() {
    List<String> tagsToCheck = new ArrayList<>();
    tagsToCheck.add(TAG1);
    tagsToCheck.add(TAG2);
    CreaterepoTreeCategory categoryTest = new CreaterepoTreeCategory(CATEGORY_NAME);
    assertEquals(0, categoryTest.getTags().size());
    assertEquals(CATEGORY_NAME, categoryTest.getName());
    categoryTest.addTag(TAG2);
    assertEquals(1, categoryTest.getTags().size());
    assertEquals(TAG2, categoryTest.getTags().get(0));
    categoryTest.addAllTags(tagsToCheck);
    // TAG2 should not be added again, hence size should = 2
    assertEquals(2, categoryTest.getTags().size());
}
Also used : CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with CreaterepoTreeCategory

use of org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory in project linuxtools by eclipse.

the class MetadataPage method refreshTree.

/**
 * 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);
            }
        }
    }
}
Also used : CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 3 with CreaterepoTreeCategory

use of org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory in project linuxtools by eclipse.

the class MetadataPage method addTag.

/**
 * 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.
 */
private 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);
        }
    }
}
Also used : CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with CreaterepoTreeCategory

use of org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory in project linuxtools by eclipse.

the class CreaterepoTreeTest method testTreeViewerPreferences.

/**
 * Test if the treeviewer properly loads the preferences.
 *
 * @throws BackingStoreException
 */
@Test
public void testTreeViewerPreferences() throws BackingStoreException {
    addTestPreferences();
    Display.getDefault().syncExec(() -> {
        initViewer();
        for (TreeItem treeItem : tree.getItems()) {
            if (treeItem.getData() instanceof CreaterepoTreeCategory) {
                CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
                // make sure the categories are still correct
                assertTrue(CORRECT_CATEGORIES.containsKey(category.getName()));
                // assert that the number of tags stored is the correct
                // amount
                assertEquals(CORRECT_CATEGORIES.get(category.getName()).intValue(), category.getTags().size());
            }
        }
        // do 1 test to make sure the tags were properly stored/loaded
        for (TreeItem treeItem : tree.getItems()) {
            if (treeItem.getData() instanceof CreaterepoTreeCategory) {
                CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
                // way
                if (category.getName().equals(CreaterepoPreferenceConstants.PREF_DISTRO_TAG)) {
                    assertArrayEquals(DISTRO_TAGS, category.getTags().toArray());
                    break;
                }
            }
        }
    });
}
Also used : CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) TreeItem(org.eclipse.swt.widgets.TreeItem) Test(org.junit.Test)

Example 5 with CreaterepoTreeCategory

use of org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory in project linuxtools by eclipse.

the class MetadataPage method createFormContent.

@Override
protected void createFormContent(IManagedForm managedForm) {
    // setting up the form page
    super.createFormContent(managedForm);
    GridLayout layout = new GridLayout();
    toolkit = managedForm.getToolkit();
    ScrolledForm form = managedForm.getForm();
    form.setText(Messages.MetadataPage_formHeaderText);
    form.setImage(Activator.getImageDescriptor(HEADER_ICON).createImage());
    ToolBarManager toolbarManager = (ToolBarManager) form.getToolBarManager();
    toolkit.decorateFormHeading(form.getForm());
    // add the menuContribution from MANIFEST.MF to the form
    IMenuService menuService = getSite().getService(IMenuService.class);
    menuService.populateContributionManager(toolbarManager, MENU_URI);
    toolbarManager.update(true);
    layout = new GridLayout();
    layout.marginWidth = 6;
    layout.marginHeight = 12;
    form.getBody().setLayout(layout);
    // --------------------------------- REVISION SECTION START ----------
    // Section and its client area to manage updating revision info
    Section revSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    layout = new GridLayout();
    GridData data = new GridData();
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    revSection.setText(Messages.MetadataPage_sectionTitleRevision);
    revSection.setDescription(Messages.MetadataPage_sectionInstructionRevision);
    revSection.setLayoutData(data);
    // the client area containing the editing fields
    Composite sectionClient = toolkit.createComposite(revSection);
    layout = new GridLayout(2, false);
    layout.marginWidth = 1;
    layout.marginHeight = 7;
    sectionClient.setLayout(layout);
    Text revisionTxt = createTextFieldWithLabel(sectionClient, Messages.MetadataPage_labelRevision);
    String prefRevisionTxt = eclipsePreferences.get(CreaterepoPreferenceConstants.PREF_REVISION, ICreaterepoConstants.EMPTY_STRING);
    if (!prefRevisionTxt.isEmpty()) {
        revisionTxt.setText(prefRevisionTxt);
    }
    revisionTxt.addSelectionListener(SelectionListener.widgetDefaultSelectedAdapter(e -> {
        String revisionText = revisionTxt.getText().trim();
        savePreferences(CreaterepoPreferenceConstants.PREF_REVISION, revisionText);
    }));
    revSection.setClient(sectionClient);
    // ---------- REVISION SECTION END
    // --------------------------------- TAGS SECTION START ----------
    // Section and its client area to manage tags
    Section tagSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    layout = new GridLayout();
    tagSection.setText(Messages.MetadataPage_sectionTitleTags);
    tagSection.setDescription(Messages.MetadataPage_sectionInstructionTags);
    tagSection.setLayoutData(expandComposite());
    // the client area containing the tags
    Composite sectionClientTags = toolkit.createComposite(tagSection);
    layout = new GridLayout(2, false);
    layout.marginWidth = 1;
    layout.marginHeight = 7;
    sectionClientTags.setLayout(layout);
    tagTxt = createTextFieldWithLabel(sectionClientTags, Messages.MetadataPage_labelTags);
    tagTxt.addSelectionListener(new AddTagButtonListener());
    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 model = new CreaterepoCategoryModel(project);
    tagsTreeViewer.setInput(model);
    // change the tag text field on change (make editing tag easier)
    tagsTreeViewer.addSelectionChangedListener(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(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
    Composite buttonList = toolkit.createComposite(sectionClientTags);
    layout = new GridLayout();
    data = new GridData(SWT.BEGINNING, SWT.FILL, false, true);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    buttonList.setLayout(layout);
    buttonList.setLayoutData(data);
    createPushButton(buttonList, Messages.MetadataPage_buttonAddTag, toolkit).addSelectionListener(new AddTagButtonListener());
    createPushButton(buttonList, Messages.MetadataPage_buttonEditTag, toolkit).addSelectionListener(new EditTagButtonListener());
    createPushButton(buttonList, Messages.MetadataPage_buttonRemoveTag, toolkit).addSelectionListener(new RemoveTagButtonListener());
    tagSection.setClient(sectionClientTags);
    // ---------- TAGS SECTION END
    refreshTree();
    managedForm.refresh();
}
Also used : IMenuService(org.eclipse.ui.menus.IMenuService) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) ICreaterepoConstants(org.eclipse.linuxtools.internal.rpm.createrepo.ICreaterepoConstants) BackingStoreException(org.osgi.service.prefs.BackingStoreException) CreaterepoPreferenceConstants(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoPreferenceConstants) Composite(org.eclipse.swt.widgets.Composite) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) CreaterepoTreeContentProvider(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeContentProvider) GridData(org.eclipse.swt.layout.GridData) Activator(org.eclipse.linuxtools.internal.rpm.createrepo.Activator) Section(org.eclipse.ui.forms.widgets.Section) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) CreaterepoTreeLabelProvider(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeLabelProvider) Button(org.eclipse.swt.widgets.Button) CreaterepoCategoryModel(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoCategoryModel) FormEditor(org.eclipse.ui.forms.editor.FormEditor) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IManagedForm(org.eclipse.ui.forms.IManagedForm) TreeItem(org.eclipse.swt.widgets.TreeItem) Messages(org.eclipse.linuxtools.internal.rpm.createrepo.Messages) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) ToolBarManager(org.eclipse.jface.action.ToolBarManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) FormPage(org.eclipse.ui.forms.editor.FormPage) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) CreaterepoTreeContentProvider(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CreaterepoTreeLabelProvider(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeLabelProvider) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Section(org.eclipse.ui.forms.widgets.Section) ToolBarManager(org.eclipse.jface.action.ToolBarManager) CreaterepoTreeCategory(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory) GridLayout(org.eclipse.swt.layout.GridLayout) IMenuService(org.eclipse.ui.menus.IMenuService) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) GridData(org.eclipse.swt.layout.GridData) CreaterepoCategoryModel(org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoCategoryModel)

Aggregations

CreaterepoTreeCategory (org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory)8 Test (org.junit.Test)5 Tree (org.eclipse.swt.widgets.Tree)4 TreeItem (org.eclipse.swt.widgets.TreeItem)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ArrayList (java.util.ArrayList)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 ToolBarManager (org.eclipse.jface.action.ToolBarManager)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Activator (org.eclipse.linuxtools.internal.rpm.createrepo.Activator)1 CreaterepoPreferenceConstants (org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoPreferenceConstants)1 CreaterepoProject (org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject)1 ICreaterepoConstants (org.eclipse.linuxtools.internal.rpm.createrepo.ICreaterepoConstants)1 Messages (org.eclipse.linuxtools.internal.rpm.createrepo.Messages)1 CreaterepoCategoryModel (org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoCategoryModel)1 CreaterepoTreeContentProvider (org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeContentProvider)1 CreaterepoTreeLabelProvider (org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeLabelProvider)1 SWT (org.eclipse.swt.SWT)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1