use of com.devonfw.cobigen.eclipse.wizard.common.model.stubs.IResourceStub 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.IResourceStub 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.IResourceStub in project cobigen by devonfw.
the class SelectFileContentProvider method stubNonExistentChildren.
/**
* Stubs all non existent resources, which are selected to be generated
*
* @param parentElement parent {@link IJavaElement} to retrieve the children from
* @param stubbedChildren the so far stubbed resources and similarly the output of this method as new stubbed
* resources will be added to this list. This is necessary in order to avoid duplicates in this list.
*/
private void stubNonExistentChildren(IResource parentElement, List<Object> stubbedChildren) {
String debugInfo;
IPath parentPath = parentElement.getFullPath();
List<String> nonExistentChildren = getNonExistentChildren(parentPath);
for (String path : nonExistentChildren) {
IResourceStub resourceStub = null;
IPath childPath = new Path(path);
IPath childPathFragment = childPath.removeFirstSegments(parentPath.segmentCount());
if (childPathFragment.segmentCount() > 1) {
// target path is no atomic child -> stub next element if necessary
childPathFragment = childPathFragment.removeFirstSegments(1);
IPath atomicChildPath = new Path(path);
atomicChildPath = atomicChildPath.removeLastSegments(childPathFragment.segmentCount());
// parent
if (ResourcesPlugin.getWorkspace().getRoot().exists(atomicChildPath)) {
continue;
} else if (this._cachedProvidedResources.containsKey(atomicChildPath.toString())) {
// if already seen, just get it and skip creation
Object cachedStub = this._cachedProvidedResources.get(atomicChildPath.toString());
if (!stubbedChildren.contains(cachedStub)) {
stubbedChildren.add(cachedStub);
}
continue;
}
if (targetIsFile(atomicChildPath, nonExistentChildren)) {
resourceStub = new IFileStub();
debugInfo = "File";
} else {
resourceStub = new IFolderStub();
debugInfo = "Folder";
}
resourceStub.setFullPath(atomicChildPath);
} else if (childPathFragment.segmentCount() == 1) {
if (this._cachedProvidedResources.containsKey(childPath.toString())) {
// if already seen, just get it and skip creation
Object cachedStub = this._cachedProvidedResources.get(childPath.toString());
if (!stubbedChildren.contains(cachedStub)) {
stubbedChildren.add(cachedStub);
}
continue;
}
if (targetIsFile(childPath, nonExistentChildren)) {
resourceStub = new IFileStub();
debugInfo = "File";
} else {
resourceStub = new IFolderStub();
debugInfo = "Folder";
}
resourceStub.setFullPath(childPath);
} else {
// no child of parentPath
continue;
}
if (!stubbedChildren.contains(resourceStub)) {
stubbedChildren.add(resourceStub);
this._cachedProvidedResources.put(resourceStub.getFullPath().toString(), resourceStub);
}
LOG.debug("Stub created for {} with name '{}' and path '{}'", debugInfo, resourceStub.getName(), resourceStub.getFullPath().toString());
}
}
Aggregations