use of com.archimatetool.model.IProfile 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.model.IProfile in project archi by archimatetool.
the class ProfilesManagerDialog method createNewProfile.
/**
* Create a new Profile and add it to the temp profiles list
*/
private void createNewProfile() {
IProfile profile = IArchimateFactory.eINSTANCE.createProfile();
profile.setConceptType(fDefaultClass.getName());
profile.setName(generateNewProfileName(profile.getConceptType()));
fProfilesTemp.put(profile.getId(), profile);
// fTableViewer.applyEditorValue(); // complete any current editing
fTableViewer.refresh();
fTableViewer.editElement(profile, 1);
}
use of com.archimatetool.model.IProfile in project archi by archimatetool.
the class ProfilesManagerDialog method chooseImage.
/**
* Choose an image from the dialog and apply to selected profiles
*/
private void chooseImage() {
IStructuredSelection selection = fTableViewer.getStructuredSelection();
if (!selection.isEmpty()) {
IProfile firstSelected = (IProfile) selection.getFirstElement();
ImageManagerDialog dialog = new ImageManagerDialog(getParentShell());
dialog.setSelected(fArchimateModel, firstSelected.getImagePath());
if (dialog.open() == Window.OK) {
try {
IArchiveManager archiveManager = (IArchiveManager) fArchimateModel.getAdapter(IArchiveManager.class);
String path = null;
// Image from file
if (dialog.getUserSelectedFile() != null && dialog.getUserSelectedFile().exists()) {
path = archiveManager.addImageFromFile(dialog.getUserSelectedFile());
} else // Existing image which could be in this model or a different model
if (dialog.getUserSelectedImagePath() != null) {
if (dialog.getUserSelectedModel() != fArchimateModel) {
// Different model
IArchiveManager selectedArchiveManager = (IArchiveManager) dialog.getUserSelectedModel().getAdapter(IArchiveManager.class);
path = archiveManager.copyImageBytes(selectedArchiveManager, dialog.getUserSelectedImagePath());
} else {
// Same model
path = dialog.getUserSelectedImagePath();
}
}
if (path != null) {
// Apply the image path to Profiles that can have an image
for (Object o : selection.toList()) {
IProfile profile = (IProfile) o;
if (canHaveImage(profile)) {
profile.setImagePath(path);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
// $NON-NLS-1$
Logger.logError("Could not create image!", ex);
}
// Select to update image preview
fTableViewer.setSelection(selection);
}
}
}
use of com.archimatetool.model.IProfile in project archi by archimatetool.
the class ProfilesManagerDialog method createTableControl.
/**
* Create the Table
*/
private void createTableControl(Composite parent) {
Composite tableComp = new Composite(parent, SWT.BORDER);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComp.setLayout(tableLayout);
GridDataFactory.create(GridData.FILL_BOTH).applyTo(tableComp);
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
GridDataFactory.create(GridData.FILL_BOTH).applyTo(fTableViewer.getControl());
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Edit cell on single-click and add Tab key traversal
TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer), ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
fTableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return ((IProfile) e1).getName().compareToIgnoreCase(((IProfile) e2).getName());
}
});
// Columns
// Icon
TableViewerColumn columnIcon = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(columnIcon.getColumn(), new ColumnWeightData(5, true));
// Name
TableViewerColumn columnName = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnName.getColumn().setText(Messages.ProfilesManagerDialog_7);
tableLayout.setColumnData(columnName.getColumn(), new ColumnWeightData(50, true));
columnName.setEditingSupport(new NameEditingSupport(fTableViewer));
// Restricted to Concept Type
TableViewerColumn columnConceptType = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
columnConceptType.getColumn().setText(Messages.ProfilesManagerDialog_8);
tableLayout.setColumnData(columnConceptType.getColumn(), new ColumnWeightData(35, true));
columnConceptType.setEditingSupport(new ConceptTypeEditingSupport(fTableViewer));
// Usage
TableViewerColumn columnUsage = new TableViewerColumn(fTableViewer, SWT.NONE, 3);
columnUsage.getColumn().setText(Messages.ProfilesManagerDialog_9);
tableLayout.setColumnData(columnUsage.getColumn(), new ColumnWeightData(10, true));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return fProfilesTemp.values().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = event.getStructuredSelection();
boolean enabled = !selection.isEmpty();
// Disable/enable some actions
fActionDelete.setEnabled(enabled);
fButtonDelete.setEnabled(enabled);
fActionChooseImage.setEnabled(enabled);
fActionClearImage.setEnabled(false);
// Image buttons/actions depend on some factors...
for (Object o : selection) {
IProfile profile = (IProfile) o;
// If any selected Profile can't have an image then this is disabled
if (!canHaveImage(profile)) {
fActionChooseImage.setEnabled(false);
}
// Enable clear image only if there is one image to clear in the selection
if (profile.getImagePath() != null) {
fActionClearImage.setEnabled(true);
}
}
fImageButton.setEnabled(fActionChooseImage.isEnabled() || fActionClearImage.isEnabled());
// Update Image Preview
updateImagePreview();
}
});
/*
* Table Double-click
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
// Get Table item
Point pt = new Point(e.x, e.y);
TableItem item = fTableViewer.getTable().getItem(pt);
// Double-click into empty table creates new Profile
if (item == null) {
createNewProfile();
}
});
// anything will do //$NON-NLS-1$
fTableViewer.setInput("");
}
use of com.archimatetool.model.IProfile in project archi by archimatetool.
the class CSVExporterTests method testCreateElementRow.
@Test
public void testCreateElementRow() {
IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
element.setId("a1234567");
element.setName("The Main Man");
element.setDocumentation("This is the Documentation");
IProfile profile = IArchimateFactory.eINSTANCE.createProfile();
profile.setName("Profile");
element.getProfiles().add(profile);
assertEquals("\"a1234567\",\"BusinessActor\",\"The Main Man\",\"This is the Documentation\",\"Profile\"", exporter.createElementRow(element));
}
Aggregations