Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5846fa10209bd00496fa7726e63a1e5ddbd402fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright (c) 2013, 2018 Red Hat Inc. and others.
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Neil Guzman - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.createrepo.form;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.eclipse.linuxtools.internal.rpm.createrepo.listener.CreaterepoResourceChangeListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.ide.ResourceUtil;

/**
 * The repo file form editor will allow the user to edit the .repo file,
 * import/remove RPMs, and customize the execution and/or the repo metadata that
 * is generated.
 */
public class RepoFormEditor extends FormEditor {

    public static final String EDITOR_ID = "org.eclipse.linuxtools.rpm.createrepo.repoEditor"; //$NON-NLS-1$

    private CreaterepoProject project;
    private TextEditor editor;
    private IResourceChangeListener resourceChangeListener;

    @Override
    public void init(IEditorSite site, IEditorInput input)
            throws PartInitException {
        super.init(site, input);
        IFile file = ResourceUtil.getFile(input);
        setPartName(file.getName());
        try {
            project = new CreaterepoProject(file.getProject(), file);
        } catch (CoreException e) {
            Activator.logError(
                    Messages.RepoFormEditor_errorInitializingProject, e);
        }
        resourceChangeListener = new CreaterepoResourceChangeListener(project);
        ResourcesPlugin.getWorkspace().addResourceChangeListener(
                resourceChangeListener);
    }

    @Override
    public void dispose() {
        ResourcesPlugin.getWorkspace().removeResourceChangeListener(
                resourceChangeListener);
        super.dispose();
    }

    @Override
    public void doSave(IProgressMonitor monitor) {
        editor.doSave(monitor);
    }

    @Override
    public void doSaveAs() {
        editor.doSaveAs();
    }

    @Override
    public boolean isSaveAsAllowed() {
        return true;
    }

    @Override
    protected void addPages() {
        try {
            createImportsPage();
            createMetadataPage();
            createEditorPage();
        } catch (PartInitException e) {
            Activator
                    .logError(Messages.RepoFormEditor_errorInitializingForm, e);
        }
    }

    /**
     * Creates page for importing RPMs from the workspace or the file system.
     *
     * @throws PartInitException
     */
    private void createImportsPage() throws PartInitException {
        FormPage composite = new ImportRPMsPage(this, project);
        addPage(composite);
    }

    /**
     * Creates page allowing the user to modify some of the data in the
     * repomd.xml as well as some options when customizing the execution of the
     * createrepo command. The default execution would satisfy most users.
     *
     * @throws PartInitException
     */
    private void createMetadataPage() throws PartInitException {
        FormPage composite = new MetadataPage(this, project);
        addPage(composite);
    }

    /**
     * Creates editor for the current .repo file.
     *
     * @throws PartInitException
     */
    private void createEditorPage() throws PartInitException {
        editor = new TextEditor();
        int index = addPage(editor, getEditorInput());
        setPageText(index, editor.getTitle());
    }

}

Back to the top