From 232845cae50b2fc44c9cc60e21b9c15628ba3dd2 Mon Sep 17 00:00:00 2001 From: Phillipus Date: Mon, 9 Dec 2024 11:58:23 +0000 Subject: [PATCH] Use a dialog to select User Properties for the Search Filter - And refactor into UserPropertiesKeySelectionDialog that can be re-used --- .../editor/propertysections/Messages.java | 6 - .../UserPropertiesSection.java | 143 +------------- .../propertysections/messages.properties | 3 - .../editor/ui/dialog/Messages.java | 10 + .../UserPropertiesKeySelectionDialog.java | 182 ++++++++++++++++++ .../editor/ui/dialog/messages.properties | 5 + .../views/tree/search/SearchFilter.java | 4 + .../views/tree/search/SearchWidget.java | 109 +++++------ .../views/tree/search/messages.properties | 2 +- 9 files changed, 258 insertions(+), 206 deletions(-) create mode 100644 com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/UserPropertiesKeySelectionDialog.java diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java index 5bffe4ff3..7664a71ce 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/Messages.java @@ -345,16 +345,10 @@ public class Messages extends NLS { public static String UserPropertiesSection_14; - public static String UserPropertiesSection_15; - public static String UserPropertiesSection_16; public static String UserPropertiesSection_17; - public static String UserPropertiesSection_18; - - public static String UserPropertiesSection_19; - public static String UserPropertiesSection_2; public static String UserPropertiesSection_20; diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/UserPropertiesSection.java b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/UserPropertiesSection.java index e9f883f0a..c29b86f5a 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/UserPropertiesSection.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/UserPropertiesSection.java @@ -41,7 +41,6 @@ import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CellLabelProvider; -import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ColumnViewer; import org.eclipse.jface.viewers.ColumnViewerEditor; import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; @@ -52,7 +51,6 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.viewers.TableViewerEditor; @@ -68,14 +66,10 @@ import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; @@ -93,9 +87,9 @@ import com.archimatetool.editor.preferences.IPreferenceConstants; import com.archimatetool.editor.ui.IArchiImages; import com.archimatetool.editor.ui.ThemeUtils; -import com.archimatetool.editor.ui.components.ExtendedTitleAreaDialog; import com.archimatetool.editor.ui.components.GlobalActionDisablementHandler; import com.archimatetool.editor.ui.components.StringComboBoxCellEditor; +import com.archimatetool.editor.ui.dialog.UserPropertiesKeySelectionDialog; import com.archimatetool.editor.utils.HTMLUtils; import com.archimatetool.editor.utils.StringUtils; import com.archimatetool.model.IArchimateFactory; @@ -1097,7 +1091,7 @@ private NewMultiplePropertiesAction() { @Override public void run() { if(isAlive(getFirstSelectedElement())) { - MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell(), getAllUniquePropertyKeysForModel(MAX_ITEMS_ALL)); + MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell(), List.of(getAllUniquePropertyKeysForModel(MAX_ITEMS_ALL))); if(dialog.open() != Window.CANCEL) { List newKeys = dialog.getSelectedKeys(); if(newKeys == null || newKeys.isEmpty()) { @@ -1367,147 +1361,28 @@ public void dispose() { // // ----------------------------------------------------------------------------------------------------------------- - private static class MultipleAddDialog extends ExtendedTitleAreaDialog { - private CheckboxTableViewer tableViewer; - private Button buttonSelectAll, buttonDeselectAll; - - private String[] keys; - private List selectedKeys; - - public MultipleAddDialog(Shell parentShell, String[] keys) { - super(parentShell, "ArchimatePropertiesMultipleAddDialog"); //$NON-NLS-1$ - setTitleImage(IArchiImages.ImageFactory.getImage(IArchiImages.ECLIPSE_IMAGE_IMPORT_PREF_WIZARD)); - setShellStyle(getShellStyle() | SWT.RESIZE); - this.keys = keys; - } - - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(Messages.UserPropertiesSection_15); - } - - @Override - protected Control createButtonBar(Composite parent) { - Control c = super.createButtonBar(parent); - if(keys.length == 0) { - getButton(IDialogConstants.OK_ID).setEnabled(false); - buttonSelectAll.setEnabled(false); - buttonDeselectAll.setEnabled(false); - } - return c; + private static class MultipleAddDialog extends UserPropertiesKeySelectionDialog { + public MultipleAddDialog(Shell parentShell, List keys) { + super(parentShell, keys, null); } @Override protected Control createDialogArea(Composite parent) { - // Help - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); - + Composite composite = (Composite)super.createDialogArea(parent); setTitle(Messages.UserPropertiesSection_16); setMessage(Messages.UserPropertiesSection_17); - - Composite composite = (Composite)super.createDialogArea(parent); - - Composite client = new Composite(composite, SWT.NULL); - GridLayout layout = new GridLayout(2, false); - client.setLayout(layout); - client.setLayoutData(new GridData(GridData.FILL_BOTH)); - - createTableControl(client); - createButtonPanel(client); - return composite; } - private void createTableControl(Composite parent) { - Composite tableComp = new Composite(parent, SWT.BORDER); - TableColumnLayout tableLayout = new TableColumnLayout(); - tableComp.setLayout(tableLayout); - tableComp.setLayoutData(new GridData(GridData.FILL_BOTH)); - - tableViewer = CheckboxTableViewer.newCheckList(tableComp, SWT.MULTI | SWT.FULL_SELECTION); - tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); - - tableViewer.getTable().setLinesVisible(true); - - // Column - TableViewerColumn columnKey = new TableViewerColumn(tableViewer, SWT.NONE, 0); - tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(100, true)); - - // Content Provider - tableViewer.setContentProvider(new IStructuredContentProvider() { - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - @Override - public Object[] getElements(Object inputElement) { - return keys; - } - - @Override - public void dispose() { - } - }); - - // Label Provider - tableViewer.setLabelProvider(new LabelProvider()); - tableViewer.setInput(keys); - } - - private void createButtonPanel(Composite parent) { - Composite client = new Composite(parent, SWT.NULL); - - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - client.setLayout(layout); - - GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); - client.setLayoutData(gd); - - buttonSelectAll = new Button(client, SWT.PUSH); - buttonSelectAll.setText(Messages.UserPropertiesSection_18); - gd = new GridData(GridData.FILL_HORIZONTAL); - buttonSelectAll.setLayoutData(gd); - buttonSelectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { - tableViewer.setCheckedElements(keys); - })); - - buttonDeselectAll = new Button(client, SWT.PUSH); - buttonDeselectAll.setText(Messages.UserPropertiesSection_19); - gd = new GridData(GridData.FILL_HORIZONTAL); - buttonDeselectAll.setLayoutData(gd); - buttonDeselectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { - 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 buttonPressed(int buttonId) { - selectedKeys = new ArrayList<>(); - for(Object o : tableViewer.getCheckedElements()) { - selectedKeys.add((String)o); + + if(keys.size() == 0) { + getButton(IDialogConstants.CLIENT_ID).setEnabled(false); } - - setReturnCode(buttonId); - close(); - } - - List getSelectedKeys() { - return selectedKeys; - } - - @Override - protected Point getDefaultDialogSize() { - return new Point(400, 250); } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties index a57e9620d..12a73676d 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/propertysections/messages.properties @@ -189,11 +189,8 @@ UserPropertiesSection_11=Set Property Value UserPropertiesSection_12=New Property UserPropertiesSection_13=Move Property UserPropertiesSection_14=Sort Properties -UserPropertiesSection_15=Properties UserPropertiesSection_16=Add Multiple Properties UserPropertiesSection_17=Select the Properties to add to this Element -UserPropertiesSection_18=Select All -UserPropertiesSection_19=Deselect All UserPropertiesSection_2=New UserPropertiesSection_20=Add Properties UserPropertiesSection_21=Double-click on icon to open link in Browser diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/Messages.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/Messages.java index 015100d5e..5f3ef59c0 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/Messages.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/Messages.java @@ -27,6 +27,16 @@ public class Messages extends NLS { public static String RelationshipsMatrixDialog_1; public static String RelationshipsMatrixDialog_2; + + public static String UserPropertiesKeySelectionDialog_0; + + public static String UserPropertiesKeySelectionDialog_1; + + public static String UserPropertiesKeySelectionDialog_2; + + public static String UserPropertiesKeySelectionDialog_3; + + public static String UserPropertiesKeySelectionDialog_4; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/UserPropertiesKeySelectionDialog.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/UserPropertiesKeySelectionDialog.java new file mode 100644 index 000000000..1340d59f0 --- /dev/null +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/UserPropertiesKeySelectionDialog.java @@ -0,0 +1,182 @@ +package com.archimatetool.editor.ui.dialog; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +import com.archimatetool.editor.ui.IArchiImages; +import com.archimatetool.editor.ui.components.ExtendedTitleAreaDialog; + + + +/** + * User Properties Key Selection Dialog + * + * @author Phillip Beauvoir + */ +public class UserPropertiesKeySelectionDialog extends ExtendedTitleAreaDialog { + + private static String HELP_ID = "com.archimatetool.help.userProperties"; //$NON-NLS-1$ + + protected CheckboxTableViewer tableViewer; + protected Button buttonSelectAll, buttonDeselectAll; + + protected List keys; + protected List selectedKeys; + + /** + * @param parentShell + * @param keys The list of property keys + * @param selected A list of property keys to select. Can be null. + */ + public UserPropertiesKeySelectionDialog(Shell parentShell, List keys, List selected) { + super(parentShell, "UserPropertiesKeySelectionDialog"); //$NON-NLS-1$ + setTitleImage(IArchiImages.ImageFactory.getImage(IArchiImages.ECLIPSE_IMAGE_IMPORT_PREF_WIZARD)); + setShellStyle(getShellStyle() | SWT.RESIZE); + + this.keys = keys; + selectedKeys = selected; + } + + @Override + protected Control createButtonBar(Composite parent) { + Control c = super.createButtonBar(parent); + + if(keys.size() == 0) { + getButton(IDialogConstants.OK_ID).setEnabled(false); + buttonSelectAll.setEnabled(false); + buttonDeselectAll.setEnabled(false); + } + + return c; + } + + @Override + protected Control createDialogArea(Composite parent) { + // Help + PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID); + + getShell().setText(Messages.UserPropertiesKeySelectionDialog_0); + setTitle(Messages.UserPropertiesKeySelectionDialog_1); + setMessage(Messages.UserPropertiesKeySelectionDialog_2); + + Composite composite = (Composite)super.createDialogArea(parent); + + Composite client = new Composite(composite, SWT.NULL); + GridLayout layout = new GridLayout(2, false); + client.setLayout(layout); + client.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createTableControl(client); + createButtonPanel(client); + + return composite; + } + + protected void createTableControl(Composite parent) { + Composite tableComp = new Composite(parent, SWT.BORDER); + TableColumnLayout tableLayout = new TableColumnLayout(); + tableComp.setLayout(tableLayout); + tableComp.setLayoutData(new GridData(GridData.FILL_BOTH)); + + tableViewer = CheckboxTableViewer.newCheckList(tableComp, SWT.MULTI | SWT.FULL_SELECTION); + tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); + + tableViewer.getTable().setLinesVisible(true); + + // Columns + TableViewerColumn columnKey = new TableViewerColumn(tableViewer, SWT.NONE, 0); + tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(100, true)); + + // Content Provider + tableViewer.setContentProvider(new IStructuredContentProvider() { + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public Object[] getElements(Object inputElement) { + return keys.toArray(); + } + + @Override + public void dispose() { + } + }); + + // Label Provider + tableViewer.setLabelProvider(new LabelProvider()); + + tableViewer.setInput(keys); + + if(selectedKeys != null) { + tableViewer.setCheckedElements(selectedKeys.toArray()); + } + } + + protected void createButtonPanel(Composite parent) { + Composite client = new Composite(parent, SWT.NULL); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + client.setLayout(layout); + + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + client.setLayoutData(gd); + + buttonSelectAll = new Button(client, SWT.PUSH); + buttonSelectAll.setText(Messages.UserPropertiesKeySelectionDialog_3); + gd = new GridData(GridData.FILL_HORIZONTAL); + buttonSelectAll.setLayoutData(gd); + buttonSelectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { + tableViewer.setCheckedElements(keys.toArray()); + })); + + buttonDeselectAll = new Button(client, SWT.PUSH); + buttonDeselectAll.setText(Messages.UserPropertiesKeySelectionDialog_4); + gd = new GridData(GridData.FILL_HORIZONTAL); + buttonDeselectAll.setLayoutData(gd); + buttonDeselectAll.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { + tableViewer.setCheckedElements(new Object[] {}); + })); + } + + @Override + protected void buttonPressed(int buttonId) { + selectedKeys = new ArrayList<>(); + for(Object o : tableViewer.getCheckedElements()) { + selectedKeys.add((String)o); + } + + setReturnCode(buttonId); + close(); + } + + public List getSelectedKeys() { + return selectedKeys; + } + + @Override + protected Point getDefaultDialogSize() { + return new Point(400, 250); + } +} \ No newline at end of file diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/messages.properties index 05e867d91..0fdac9117 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/dialog/messages.properties @@ -9,3 +9,8 @@ AboutDialog_7=Check for Updates... RelationshipsMatrixDialog_0=ArchiMate Relationships RelationshipsMatrixDialog_1=These are the allowed relationships between elements as per the ArchiMate 3.2 specification. RelationshipsMatrixDialog_2=Done +UserPropertiesKeySelectionDialog_0=Properties +UserPropertiesKeySelectionDialog_1=Select Properties +UserPropertiesKeySelectionDialog_2=Select Property Keys +UserPropertiesKeySelectionDialog_3=Select All +UserPropertiesKeySelectionDialog_4=Deselect All diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java index a76b70c02..2834438fa 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java @@ -234,6 +234,10 @@ void removePropertiesFilter(String key) { fPropertiesFilter.remove(key); } + Set getPropertiesFilter() { + return fPropertiesFilter; + } + void resetPropertiesFilter() { fPropertiesFilter.clear(); } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java index 95ec5e6a1..a1f178c67 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java @@ -29,6 +29,7 @@ import org.eclipse.jface.viewers.ITreeViewerListener; import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -46,6 +47,7 @@ import com.archimatetool.editor.ui.IArchiImages; import com.archimatetool.editor.ui.UIUtils; import com.archimatetool.editor.ui.components.GlobalActionDisablementHandler; +import com.archimatetool.editor.ui.dialog.UserPropertiesKeySelectionDialog; import com.archimatetool.editor.utils.PlatformUtils; import com.archimatetool.editor.utils.StringUtils; import com.archimatetool.model.IArchimateModel; @@ -75,7 +77,6 @@ public class SearchWidget extends Composite { private List fConceptActions = new ArrayList<>(); - private MenuManager fPropertiesMenu; private MenuManager fSpecializationsMenu; private Timer fKeyDelayTimer; @@ -233,9 +234,21 @@ public void run() { dropDownAction.add(fActionFilterDocumentation); // Properties - fPropertiesMenu = new MenuManager(Messages.SearchWidget_5); - dropDownAction.add(fPropertiesMenu); - populatePropertiesMenu(); + IAction actionProperties = new Action(Messages.SearchWidget_5, IAction.AS_PUSH_BUTTON) { + @Override + public void run() { + UserPropertiesKeySelectionDialog dialog = new UserPropertiesKeySelectionDialog(getShell(), getAllUniquePropertyKeys(), + new ArrayList<>(fSearchFilter.getPropertiesFilter())); + if(dialog.open() != Window.CANCEL) { + fSearchFilter.resetPropertiesFilter(); + for(String key : dialog.getSelectedKeys()) { + fSearchFilter.addPropertiesFilter(key); + } + refreshTree(); + } + } + }; + dropDownAction.add(actionProperties); dropDownAction.add(new Separator()); @@ -315,26 +328,26 @@ public void run() { dropDownAction.add(new Separator()); // Show All Folders - IAction action = new Action(Messages.SearchWidget_12, IAction.AS_CHECK_BOX) { + IAction actionFolders = new Action(Messages.SearchWidget_12, IAction.AS_CHECK_BOX) { @Override public void run() { fSearchFilter.setShowAllFolders(isChecked()); refreshTree(); } }; - action.setChecked(fSearchFilter.isShowAllFolders()); - dropDownAction.add(action); + actionFolders.setChecked(fSearchFilter.isShowAllFolders()); + dropDownAction.add(actionFolders); dropDownAction.add(new Separator()); // Reset - action = new Action(Messages.SearchWidget_13) { + IAction actionReset = new Action(Messages.SearchWidget_13) { @Override public void run() { reset(); } }; - dropDownAction.add(action); + dropDownAction.add(actionReset); // Need to update toolbar manager now toolBarmanager.update(true); @@ -350,9 +363,6 @@ private void reset() { // Don't filter on Documentation menu item fActionFilterDocumentation.setChecked(false); - // Clear & uncheck Properties menu items - populatePropertiesMenu(); - // Clear & uncheck Specializations menu items populateSpecializationsMenu(); @@ -376,7 +386,6 @@ private void reset() { */ public void softReset() { // Clear & Reset Properties - populatePropertiesMenu(); fSearchFilter.resetPropertiesFilter(); // Clear & Reset Specializations @@ -414,56 +423,33 @@ public ImageDescriptor getImageDescriptor() { return action; } - private void populatePropertiesMenu() { - fPropertiesMenu.removeAll(); - - // Models that are loaded are the ones in the Models Tree - Set set = new LinkedHashSet<>(); // LinkedHashSet is faster when sorting - - for(IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) { - getAllUniquePropertyKeysForModel(model, set); - } - - List list = new ArrayList<>(set); - - // Sort alphabetically, but don't use Collator.getInstance() as it's too slow - list.sort((s1, s2) -> s1.compareToIgnoreCase(s2)); - - // Limit to a sensible menu size - if(list.size() > 1000) { - list = list.subList(0, 999); - } - - for(String key : list) { - IAction action = new Action(key, IAction.AS_CHECK_BOX) { - @Override - public void run() { - if(isChecked()) { - fSearchFilter.addPropertiesFilter(key); - } - else { - fSearchFilter.removePropertiesFilter(key); - } - refreshTree(); - } - }; - - fPropertiesMenu.add(action); - } - - fPropertiesMenu.update(true); - } - - private void getAllUniquePropertyKeysForModel(IArchimateModel model, Set set) { - for(Iterator iter = model.eAllContents(); iter.hasNext();) { - EObject element = iter.next(); - if(element instanceof IProperty property) { - String key = property.getKey(); - if(StringUtils.isSetAfterTrim(key)) { - set.add(key); - } + private List getAllUniquePropertyKeys() { + // Maximum amount of items to display when getting all unique keys + final int MAX_ITEMS = 1000000; + + Set set = new LinkedHashSet<>(); // LinkedHashSet is faster when sorting + + for(IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) { + for(Iterator iter = model.eAllContents(); iter.hasNext();) { + EObject element = iter.next(); + if(element instanceof IProperty property) { + String key = property.getKey(); + if(StringUtils.isSetAfterTrim(key)) { + set.add(key); + if(set.size() > MAX_ITEMS) { // Don't get more than this + break; + } + } + } } } + + List list = new ArrayList<>(set); + + // Sort alphabetically, but don't use Collator.getInstance() as it's too slow + list.sort((s1, s2) -> s1.compareToIgnoreCase(s2)); + + return list; } private void populateSpecializationsMenu() { @@ -586,7 +572,6 @@ public void dispose() { fViewer = null; fSearchFilter = null; fConceptActions = null; - fPropertiesMenu = null; fSpecializationsMenu = null; } } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/messages.properties b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/messages.properties index b83751a23..be5f3865b 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/messages.properties +++ b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/messages.properties @@ -11,7 +11,7 @@ SearchWidget_17=Views SearchWidget_2=Documentation SearchWidget_3=Search in Documentation SearchWidget_4=Filter Options -SearchWidget_5=Properties +SearchWidget_5=Properties... SearchWidget_6=Business SearchWidget_7=Application SearchWidget_8=Technology && Physical