use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.OffWorkspaceResourceTreeNode in project cobigen by devonfw.
the class CheckStateListener method selectNewResources.
/**
* Sets all resources which will be created to be initially selected
*/
private void selectNewResources() {
CheckboxTreeViewer resourcesTree = this.page.getResourcesTree();
LinkedList<Object> worklist = Lists.newLinkedList(Arrays.asList(((SelectFileContentProvider) resourcesTree.getContentProvider()).getElements(resourcesTree.getInput())));
while (worklist.peek() != null) {
Object o = worklist.poll();
if (o instanceof IJavaElementStub || o instanceof IResourceStub || (o instanceof OffWorkspaceResourceTreeNode && !Files.exists(((OffWorkspaceResourceTreeNode) o).getAbsolutePath()))) {
resourcesTree.setChecked(o, true);
}
worklist.addAll(Arrays.asList(((SelectFileContentProvider) resourcesTree.getContentProvider()).getChildren(o)));
}
}
use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.OffWorkspaceResourceTreeNode in project cobigen by devonfw.
the class CheckStateListener method buildOffScopeResourceTree.
/**
* Builds the {@link OffWorkspaceResourceTreeNode} for workspace external files to be generated.
*
* @param pathsStr paths as strings to be built as a tree
* @return the list of root nodes.
*/
private List<OffWorkspaceResourceTreeNode> buildOffScopeResourceTree(Set<String> pathsStr) {
Set<Path> paths = Sets.newHashSet();
for (String p : pathsStr) {
paths.add(Paths.get(p));
}
List<OffWorkspaceResourceTreeNode> rootResources = Lists.newArrayList();
Map<Path, Set<Path>> prefixToSuffixMap = Maps.newHashMap();
for (Path path : paths) {
MapUtils.deepMapAdd(prefixToSuffixMap, path.getRoot(), path.subpath(0, path.getNameCount()));
}
for (Path prefix : prefixToSuffixMap.keySet()) {
OffWorkspaceResourceTreeNode curr = new OffWorkspaceResourceTreeNode(null, prefix);
buildOffScopeResourceTree(curr, prefixToSuffixMap.get(prefix));
rootResources.add(curr);
}
return rootResources;
}
use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.OffWorkspaceResourceTreeNode in project cobigen by devonfw.
the class SelectFileLabelProvider method getImage.
@Override
public Image getImage(Object element) {
String labelTextWithoutSuffix = getTextInternal(element, false);
ImageDescriptor defaultImageDescriptor = PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(labelTextWithoutSuffix);
Image result = defaultImageDescriptor.createImage();
if (element instanceof IProject) {
result = PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
} else if (element instanceof IFolder) {
result = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
} else if (element instanceof IJavaElement) {
JavaElementImageProvider p = new JavaElementImageProvider();
result = p.getImageLabel(element, JavaElementImageProvider.SMALL_ICONS);
} else if (element instanceof OffWorkspaceResourceTreeNode && ((OffWorkspaceResourceTreeNode) element).hasChildren()) {
result = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
}
return result;
}
use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.OffWorkspaceResourceTreeNode in project cobigen by devonfw.
the class AbstractGenerateWizard method userConfirmed.
/**
* Checks whether files will be overwritten by the generation process and whether the user is aware of this behavior
* and confirms it
*
* @return true, if the user confirms the changes being made or no files will be overwritten<br>
* false, otherwise
*/
private boolean userConfirmed() {
LOG.info("Check for necessary user confirmation to be displayed.");
List<Object> diff = Lists.newArrayList(this.page1.getSelectedResources());
// Delete simulated resources
Iterator<Object> it = diff.iterator();
while (it.hasNext()) {
Object r = it.next();
if (r instanceof IResourceStub || r instanceof IJavaElementStub || (r instanceof OffWorkspaceResourceTreeNode && !Files.exists(((OffWorkspaceResourceTreeNode) r).getAbsolutePath()))) {
it.remove();
}
}
// Delete mergable files
it = diff.iterator();
while (it.hasNext()) {
Object resource = it.next();
String path = null;
if (resource instanceof IJavaElement) {
try {
path = ((IJavaElement) resource).getCorrespondingResource().getFullPath().toString();
} catch (JavaModelException e) {
LOG.error("An internal java model exception occured while retrieving the java elements '{}' corresponding resource.", ((IJavaElement) resource).getElementName(), e);
}
} else if (resource instanceof IResource) {
path = ((IResource) resource).getFullPath().toString();
} else if (resource instanceof OffWorkspaceResourceTreeNode) {
path = ((OffWorkspaceResourceTreeNode) resource).getAbsolutePathStr();
}
if (path != null && this.cobigenWrapper.isMergableFile(path, this.page1.getSelectedIncrements())) {
it.remove();
}
}
if (!diff.isEmpty()) {
LOG.info("Opening dialog for user confirmation... waiting for user interaction.");
MessageDialog dialog = new MessageDialog(getShell(), "Warning!", null, "You have selected resources that are already existent and will be overwritten when proceeding.\nDo you really want to replace the existing files by newly generated ones?", MessageDialog.WARNING, new String[] { "Yes", "No" }, 1);
int result = dialog.open();
LOG.info("Got user input. Continue processing...");
if (result == 1 || result == SWT.DEFAULT) {
LOG.info("Finish user confirmation checking: user indicates to not override existing files.");
return false;
}
}
LOG.info("Finish user confirmation checking.");
return true;
}
use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.OffWorkspaceResourceTreeNode in project cobigen by devonfw.
the class CheckStateListener method buildOffScopeResourceTree.
/**
* Builds the {@link OffWorkspaceResourceTreeNode} for workspace external files. This is the recursive function to
* process a parent node and all its subsequent paths.
*
* @param parent {@link OffWorkspaceResourceTreeNode} parent node
* @param childPaths relative child paths of the parent node
*/
private void buildOffScopeResourceTree(OffWorkspaceResourceTreeNode parent, Set<Path> childPaths) {
Path emptyPath = Paths.get("");
Map<Path, Set<Path>> prefixToSuffixMap = Maps.newHashMap();
Path lonelyChildPath = emptyPath;
if (childPaths.size() == 1) {
lonelyChildPath = childPaths.iterator().next();
}
for (int i = 1; ; i++) {
prefixToSuffixMap.clear();
Path pathPrefix = emptyPath;
for (Path path : childPaths) {
pathPrefix = path.subpath(i - 1, i);
Path pathSuffix = null;
if (i < path.getNameCount()) {
pathSuffix = path.subpath(i, path.getNameCount());
}
MapUtils.deepMapAdd(prefixToSuffixMap, pathPrefix, pathSuffix);
}
if (childPaths.size() != 1 && prefixToSuffixMap.size() != 1 || childPaths.size() == 1 && i == lonelyChildPath.getNameCount() - 1) {
break;
} else {
Path newRootPath = parent.getPath().resolve(pathPrefix);
parent.setPath(newRootPath);
}
}
for (Entry<Path, Set<Path>> entry : prefixToSuffixMap.entrySet()) {
OffWorkspaceResourceTreeNode child;
if (entry.getValue().size() == 1) {
Path suffix = entry.getValue().iterator().next();
Path path = entry.getKey();
if (suffix != null) {
if (suffix.getNameCount() > 1) {
Path folderSuffix = suffix.subpath(0, suffix.getNameCount() - 1);
path = entry.getKey().resolve(folderSuffix);
child = new OffWorkspaceResourceTreeNode(parent, path);
child.addChild(new OffWorkspaceResourceTreeNode(child, suffix.subpath(suffix.getNameCount() - 1, suffix.getNameCount())));
} else {
child = new OffWorkspaceResourceTreeNode(parent, path);
child.addChild(new OffWorkspaceResourceTreeNode(child, suffix));
}
} else {
child = new OffWorkspaceResourceTreeNode(parent, path);
}
} else {
child = new OffWorkspaceResourceTreeNode(parent, entry.getKey());
if (entry.getValue() != null) {
buildOffScopeResourceTree(child, entry.getValue());
}
}
parent.addChild(child);
}
}
Aggregations