use of com.archimatetool.editor.tools.ProfilesManagerDialog in project archi by archimatetool.
the class SpecializationSection method createControls.
@Override
protected void createControls(Composite parent) {
NONE_PROFILE = IArchimateFactory.eINSTANCE.createProfile();
NONE_PROFILE.setName(Messages.SpecializationSection_0);
createLabel(parent, Messages.SpecializationSection_1, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
Composite comp = createComposite(parent, 2);
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fComboViewer = new ComboViewer(new Combo(comp, SWT.READ_ONLY | SWT.BORDER));
fComboViewer.getCombo().setVisibleItemCount(12);
fComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
getWidgetFactory().adapt(fComboViewer.getControl(), true, true);
fComboViewer.addSelectionChangedListener(event -> {
if (fIsRefreshing) {
// A Viewer will get a selectionChanged event when setting it
return;
}
IProfile profile = (IProfile) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (profile != null) {
// None Profile is null
if (profile == NONE_PROFILE) {
profile = null;
}
CompoundCommand result = new CompoundCommand();
for (EObject object : getEObjects()) {
if (isAlive(object)) {
Command cmd = new SetProfileCommand((IArchimateConcept) object, profile);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
});
fComboViewer.setContentProvider(new IStructuredContentProvider() {
/**
* Return a list of suitable Profiles in the model given the concept type of the first selected object
*/
@Override
public Object[] getElements(Object inputElement) {
IArchimateConcept firstSelected = (IArchimateConcept) getFirstSelectedObject();
if (firstSelected == null) {
return new Object[0];
}
List<IProfile> list = ArchimateModelUtils.findProfilesForConceptType(firstSelected.getArchimateModel(), firstSelected.eClass());
// Sort the Profiles by name
Collections.sort(list, new Comparator<IProfile>() {
@Override
public int compare(IProfile p1, IProfile p2) {
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
// Add the "none" Profile at the top
list.add(0, NONE_PROFILE);
return list.toArray();
}
});
fComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((IProfile) element).getName();
}
});
// $NON-NLS-1$
fComboViewer.setInput("");
// Open Profiles Manager Dialog button
Button button = getWidgetFactory().createButton(comp, null, SWT.PUSH);
// $NON-NLS-1$
button.setText(" ... ");
button.setToolTipText(Messages.SpecializationSection_2);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IArchimateModelObject selected = getFirstSelectedObject();
if (selected != null && selected.getArchimateModel() != null) {
ProfilesManagerDialog dialog = new ProfilesManagerDialog(getPart().getSite().getShell(), selected.getArchimateModel());
dialog.setDefaultClass(selected.eClass());
dialog.open();
}
}
});
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
use of com.archimatetool.editor.tools.ProfilesManagerDialog in project archi by archimatetool.
the class ShowProfilesManagerHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePart(event);
IArchimateModel model = part != null ? part.getAdapter(IArchimateModel.class) : null;
if (model != null) {
ProfilesManagerDialog dialog = new ProfilesManagerDialog(HandlerUtil.getActiveShell(event), model);
dialog.open();
}
return null;
}
Aggregations