use of org.obeonetwork.tools.requirement.wizard.util.LinkedRequirementsLabelProvider 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