Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a9ac16694339ec1a3c3e5e37e662060b59f46671 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*******************************************************************************
 * 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.form;

import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
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.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
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.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
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;

/**
 * This page will allow the user to view/edit some of the repo
 * xml metadata (i.e., repo, revision, etc.).
 */
public class MetadataPage extends FormPage {

	private FormToolkit toolkit;
	private ScrolledForm form;

	private Text revisionTxt;
	private Tree tagsTree;
	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$

	/** Default constructor. */
	public MetadataPage(FormEditor editor) {
		super(editor, Messages.MetadataPage_title, Messages.MetadataPage_title);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
	 */
	@Override
	protected void createFormContent(IManagedForm managedForm) {
		// setting up the form page
		super.createFormContent(managedForm);
		GridLayout layout = new GridLayout();
		GridData data = new GridData();
		toolkit = managedForm.getToolkit();
		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 = (IMenuService) 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();
		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);

		revisionTxt = createTextFieldWithLabel(sectionClient, Messages.MetadataPage_labelRevision);
		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);

		// TODO: create custom tree to handle tags in specific categories (distro, content, repo)
		tagsTree = toolkit.createTree(sectionClientTags, SWT.BORDER | SWT.MULTI | SWT.HORIZONTAL
				| SWT.VERTICAL | SWT.LEFT_TO_RIGHT | SWT.SMOOTH);
		tagsTree.setLayoutData(expandComposite());

		// everything to do with the buttons
		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

		managedForm.refresh();
	}

	/**
	 * Make a GridData that expands to fill both horizontally
	 * and vertically.
	 *
	 * @return The created GridData.
	 */
	private static GridData expandComposite() {
		GridData data = new GridData();
		data.verticalAlignment = GridData.FILL;
		data.horizontalAlignment = GridData.FILL;
		data.grabExcessHorizontalSpace = true;
		data.grabExcessVerticalSpace = true;
		return data;
	}
	/**
	 * Create a push style button.
	 *
	 * @param parent The parent the button will belong to.
	 * @param buttonText The text show on the button.
	 * @param toolkit The form toolkit used in creating a button.
	 * @return The button created.
	 */
	private 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());
		GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
		button.setLayoutData(gd);
		return button;
	}

	/**
	 * Create a text field with a label.
	 *
	 * @param parent The parent of the text field and label.
	 * @param labelName The name on the label.
	 * @return The newly created text field.
	 */
	protected Text createTextFieldWithLabel(Composite parent, String labelName) {
		GridData layoutData = new GridData();
		// create the label
		Label respositoryBaseURLLbl = new Label(parent, SWT.NONE);
		respositoryBaseURLLbl.setText(labelName);
		layoutData = new GridData();
		layoutData.horizontalAlignment = GridData.BEGINNING;
		layoutData.verticalAlignment = GridData.CENTER;
		// create the text field
		Text textField = new Text(parent, SWT.SINGLE);
		layoutData = new GridData();
		layoutData.horizontalIndent = 50;
		layoutData.grabExcessHorizontalSpace = true;
		layoutData.horizontalAlignment = GridData.FILL;
		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);
		return textField;
	}

	/**
	 * Handle the add button execution on the Metadata page.
	 */
	public class AddTagButtonListener extends SelectionAdapter {
		/*
		 * (non-Javadoc)
		 * @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 */}
	}

	/**
	 * Handle the edit button execution on the Metadata page.
	 */
	public class EditTagButtonListener extends SelectionAdapter {
		/*
		 * (non-Javadoc)
		 * @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 */}
	}

	/**
	 * Handle the remove button execution on the Metadata page.
	 */
	public class RemoveTagButtonListener extends SelectionAdapter {
		/*
		 * (non-Javadoc)
		 * @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 */}
	}

}

Back to the top