Skip to content

Commit

Permalink
[Properties] Add option to add only unique Properties in Multiple Add…
Browse files Browse the repository at this point in the history
… dialog
  • Loading branch information
Phillipus committed Feb 27, 2024
1 parent 1a65078 commit 3244726
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,16 @@ public class Messages extends NLS {

public static String UserPropertiesSection_22;

public static String UserPropertiesSection_23;

public static String UserPropertiesSection_3;

public static String UserPropertiesSection_4;

public static String UserPropertiesSection_5;

public static String UserPropertiesSection_6;

public static String UserPropertiesSection_7;

public static String UserPropertiesSection_8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ private NewMultiplePropertiesAction() {
public void run() {
if(isAlive(getFirstSelectedElement())) {
MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell(), getAllUniquePropertyKeysForModel(MAX_ITEMS_ALL));
if(dialog.open() == Window.OK) {
if(dialog.open() != Window.CANCEL) {
List<String> newKeys = dialog.getSelectedKeys();
if(newKeys == null || newKeys.isEmpty()) {
return;
Expand All @@ -1109,11 +1109,16 @@ public void run() {
CompoundCommand cmd = isMultiSelection() ? new CompoundCommand(Messages.UserPropertiesSection_20) :
new EObjectNonNotifyingCompoundCommand(getFirstSelectedElement(), Messages.UserPropertiesSection_20);

// Add properties that are not already present
boolean addUnique = dialog.getReturnCode() == IDialogConstants.CLIENT_ID;

for(IProperties propertiesElement : fPropertiesElements) {
if(isAlive(propertiesElement)) {
for(String key : newKeys) {
IProperty property = IArchimateFactory.eINSTANCE.createProperty(key, ""); //$NON-NLS-1$
cmd.add(new NewPropertyCommand(propertiesElement.getProperties(), property, -1));
if(!(addUnique && hasPropertyKey(propertiesElement, key))) {
IProperty property = IArchimateFactory.eINSTANCE.createProperty(key, ""); //$NON-NLS-1$
cmd.add(new NewPropertyCommand(propertiesElement.getProperties(), property, -1));
}
}
}
}
Expand All @@ -1122,6 +1127,18 @@ public void run() {
}
}
}

/**
* @return true if propertiesElement already has a property by key
*/
private boolean hasPropertyKey(IProperties propertiesElement, String key) {
for(IProperty property : propertiesElement.getProperties()) {
if(key.equals(property.getKey())) {
return true;
}
}
return false;
}
}

/**
Expand Down Expand Up @@ -1421,7 +1438,7 @@ private void createTableControl(Composite parent) {
// Column
TableViewerColumn columnKey = new TableViewerColumn(tableViewer, SWT.NONE, 0);
tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(100, true));

// Content Provider
tableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
Expand Down Expand Up @@ -1470,17 +1487,25 @@ private void createButtonPanel(Composite parent) {
tableViewer.setCheckedElements(new Object[] {});
}));
}


@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, Messages.UserPropertiesSection_6, true);
createButton(parent, IDialogConstants.CLIENT_ID, Messages.UserPropertiesSection_23, false);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

@Override
protected void okPressed() {
protected void buttonPressed(int buttonId) {
selectedKeys = new ArrayList<>();
for(Object o : tableViewer.getCheckedElements()) {
selectedKeys.add((String)o);
}

super.okPressed();
}

setReturnCode(buttonId);
close();
}

List<String> getSelectedKeys() {
return selectedKeys;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ UserPropertiesSection_2=New
UserPropertiesSection_20=Add Properties
UserPropertiesSection_21=Double-click on icon to open link in Browser
UserPropertiesSection_22=(multiple values)
UserPropertiesSection_23=Add Unique
UserPropertiesSection_3=New Multiple...
UserPropertiesSection_4=Remove
UserPropertiesSection_5=Remove Properties
UserPropertiesSection_6=Add Selected
UserPropertiesSection_7=Manage...
UserPropertiesSection_8=Move Properties
UserPropertiesSection_9=(blank)
Expand Down
Binary file modified com.archimatetool.help/help/Images/properties_user_dialog1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h2>User Properties</h2>
<img src="../Images/properties_user_dialog1.png"/><br/>
<br/>
</li>
<li>Press OK and then edit the new Values in the Properties table</li>
<li>Press "Add Selected" if you want to add all selected Properties regardless of whether they already exist in the target. Press "Add Unique" if you want to add all selected Properties that don't already exist in the target.</li>
</ol>

<p><strong>To Manage and View User Properties Globally:</strong></p>
Expand Down

0 comments on commit 3244726

Please sign in to comment.