use of org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider in project InformationSystem by ObeoNetwork.
the class LinkRequirementsDialog method createRequirementsTreeViewer.
/**
* Creates, in the given {@link Composite}, the {@link CheckBoxTreeViewer}
* allowing users to select and unselect {@link Requirement Requirements} to
* associate with the selected model element.
*
* @param parent
* the parent in which the {@link CheckboxTreeViewer} must be
* created.
* @param adapterFactory
* the {@link IAdapterFactory}.
* @param selectedEObject
* the contextual {@link EObject}.
*/
private static CheckboxTreeViewer createRequirementsTreeViewer(Composite parent, AdapterFactory adapterFactory, EObject selectedEObject) {
CheckboxTreeViewer checkBoxTreeViewer = new CheckboxTreeViewer(parent, SWT.MULTI | SWT.BORDER | SWT.CHECK);
// Layout
GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_tree.heightHint = 208;
Tree tree = checkBoxTreeViewer.getTree();
tree.setLayoutData(gd_tree);
// Contents
checkBoxTreeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
checkBoxTreeViewer.setContentProvider(new RequirementsRepositoriesContentProvider(adapterFactory));
checkBoxTreeViewer.setInput(RequirementService.findRequirementsRepositories(selectedEObject));
checkBoxTreeViewer.setCheckedElements(determineObjectsToCheck(RequirementService.getLinkedRequirementsSet(selectedEObject)).toArray());
checkBoxTreeViewer.setGrayedElements(determineObjectsToGray(RequirementService.getLinkedRequirementsSet(selectedEObject)).toArray());
// Expands the tree viewer up to all the checked elements. This way the
// user can easily add or remove requirement links with requirements
// which are located alongside already-checked requirements.
expandTreeViewerUpToCheckedElements(checkBoxTreeViewer, Arrays.asList(RequirementService.getLinkedRequirements(selectedEObject)));
checkBoxTreeViewer.addCheckStateListener(new LinkRequirementsCheckStateListener());
return checkBoxTreeViewer;
}
use of org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider in project InformationSystem by ObeoNetwork.
the class CategorySelectionPage method createControl.
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite control = new Composite(parent, SWT.NONE);
GridData gd = new GridData(GridData.FILL_BOTH);
control.setLayoutData(gd);
GridLayout layout = new GridLayout();
control.setLayout(layout);
Label intro = new Label(control, SWT.NONE);
// $NON-NLS-1$
intro.setText(RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_label"));
GridData labelData = new GridData(GridData.FILL_HORIZONTAL);
intro.setLayoutData(labelData);
categoriesViewer = new TreeViewer(control);
categoriesViewer.getControl().setLayoutData(gd);
AdapterFactory adapterFactory = ViewHelper.INSTANCE.createAdapterFactory();
categoriesViewer.setLabelProvider(new LinkedRequirementsLabelProvider(adapterFactory));
categoriesViewer.setContentProvider(new RequirementsRepositoriesContentProvider(adapterFactory) {
@Override
public Object[] getChildren(Object object) {
if (object instanceof Category) {
return ((Category) object).getSubCategories().toArray();
}
return super.getChildren(object);
}
@Override
public boolean hasChildren(Object object) {
if (object instanceof Category) {
return !((Category) object).getSubCategories().isEmpty();
}
return super.hasChildren(object);
}
});
categoriesViewer.setInput(getInput());
categoriesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
EObject selection = getTreeviewSelection();
if (selection instanceof Category) {
selectedCategory = (Category) selection;
setPageComplete(true);
} else {
setPageComplete(false);
}
createCategorie.setEnabled(selection instanceof Category || selection instanceof Repository);
}
});
createCategorie = new Button(control, SWT.PUSH);
createCategorie.setText(// $NON-NLS-1$
RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_CreateCategoryButton_title"));
createCategorie.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
InputDialog dialog = new InputDialog(getShell(), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_title"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_description"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_defaultvalue"), null);
int open = dialog.open();
if (open == Window.OK) {
Category category = RequirementFactory.eINSTANCE.createCategory();
category.setName(dialog.getValue());
if (getTreeviewSelection() instanceof Category) {
((Category) getTreeviewSelection()).getSubCategories().add(category);
} else if (getTreeviewSelection() instanceof Repository) {
((Repository) getTreeviewSelection()).getMainCategories().add(category);
}
}
}
});
createCategorie.setEnabled(false);
if (currentValue != null) {
categoriesViewer.reveal(currentValue);
categoriesViewer.setSelection(new StructuredSelection(currentValue));
}
setControl(control);
}
Aggregations