@Subscribe public void setConfiguration(IModelTransferConfiguration configuration) { if (configuration != this.importConfig) { if (this.importConfig != null) { this.importConfig.dispose(); } this.importConfig = configuration; } modelsTree.setInput(configuration); if (configuration != null) { // initialize the checkboxes initializeCheckedNodes(); // determine enablement of strip-sash-model option if (stripSashModelContent != null) { stripSashModelContent.setSelection(true); stripSashModelContent.setEnabled(configuration.hasSashModelContent()); this.importConfig.setStripSashModelContent(true); } } else if (stripSashModelContent != null) { stripSashModelContent.setSelection(true); stripSashModelContent.setEnabled(false); } validatePage(); }
@Override public void checkStateChanged(CheckStateChangedEvent event) { ITreeNode node = (ITreeNode) event.getElement(); IModelTransferNode model = node.getElement(); // apply the check state to the model if (event.getChecked()) { config.addModelToTransfer(model.getPrimaryResourceURI()); } else { config.removeModelToTransfer(model); } // propagate the check state to other occurrences of the same model for (ITreeNode next : nodes.get(model)) { event.getCheckable().setChecked(next, event.getChecked()); } }
private void initializeCheckedNodes() { final Collection<IModelTransferNode> initialSet = importConfig.getModelsToTransfer(); final ITreeContentProvider contents = (ITreeContentProvider) modelsTree.getContentProvider(); final ICheckable checkable = (ICheckable) modelsTree; final Set<IModelTransferNode> visited = Sets.newHashSet(); final Queue<Object> queue = new java.util.ArrayDeque<Object>(Arrays.asList(contents.getElements(importConfig))); for (Object next = queue.poll(); next != null; next = queue.poll()) { ITreeNode parent = (ITreeNode) next; // we must check a parent if the user initially selected it on opening the wizard // or we are importing and it is a dependent of a checked node, // or we are exporting and it is a dependency of a checked node, // or it is a model sub-unit (required dependency) of a checked node boolean mustCheck = initialSet.contains(parent.getElement()); if (mustCheck) { checkable.setChecked(next, true); } if (visited.add(parent.getElement())) { // recurse into the children for (Object child : contents.getChildren(next)) { ITreeNode treeNode = (ITreeNode) child; queue.add(treeNode); // we must check a node if either the user initially selected it on opening the wizard, // or we are importing and it is a dependent of a checked node, // or we are exporting and it is a dependency of a checked node, // or it is a model sub-unit (required dependency) of a checked node mustCheck = initialSet.contains(treeNode.getElement()) // || (isImport ? treeNode.isDependent() : treeNode.isDependency()) // || (checkable.getChecked(parent) && parent.getElement().isModelSubUnit(treeNode.getElement())); if (mustCheck) { checkable.setChecked(child, true); importConfig.addModelToTransfer(treeNode.getElement().getPrimaryResourceURI()); } } } } }
@Override protected Diagnostic doValidatePage() { Diagnostic result = Diagnostic.CANCEL_INSTANCE; if (importConfig != null) { if (importConfig.getModelsToTransfer().isEmpty()) { result = report( Diagnostic.CANCEL, NLS.bind( Messages.ModelReferencesPage_7, isImport ? Messages.ModelReferencesPage_8 : Messages.ModelReferencesPage_9)); } else { result = importConfig.validate(); } } return result; }
@Override public Object[] getElements(Object inputElement) { Object[] result = elements; if ((inputElement != config) || (result == null)) { IModelTransferConfiguration inputConfig = (IModelTransferConfiguration) inputElement; List<TreeNode> nodes = Lists.newArrayListWithCapacity(inputConfig.getModelsToTransfer().size()); for (IModelTransferNode next : inputConfig.getModelsToTransfer()) { nodes.add(new TreeNode(next)); } result = nodes.toArray(); if (inputConfig == config) { // cache the result elements = result; } } return result; }