} else if (workspaceId != null && sectionId == null & panelId == null) {
GraphicElement[] workspaceGlobalElements = getElements(workspaceId, null, null);
Set usedIds = new HashSet();
//Workspace global elements
for (int i = 0; i < workspaceGlobalElements.length; i++) {
GraphicElement element = workspaceGlobalElements[i];
usedIds.add(element.getId());
elementsToReturn.add(element);
}
//Global elements with different id
GraphicElement[] globalElements = getElements(null);
for (int i = 0; i < globalElements.length; i++) {
GraphicElement element = globalElements[i];
if (usedIds.contains(element.getId()))
continue;
elementsToReturn.add(element);
}
//Workspace non-global elements
GraphicElement[] workspaceElements = getElements(workspaceId);
for (int i = 0; i < workspaceElements.length; i++) {
GraphicElement element = workspaceElements[i];
if (element.getSectionId() == null && element.getPanelId() == null)
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
} else if (workspaceId != null && sectionId != null & panelId == null) {
//All elements defined for this section, plus workspace base elements, plus base elements with different id.
Set usedIds = new HashSet();
GraphicElement[] sectionElements = getElements(workspaceId, sectionId);
for (int i = 0; i < sectionElements.length; i++) {
GraphicElement element = sectionElements[i];
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] workspaceElements = getElements(workspaceId, null, null);
for (int i = 0; i < workspaceElements.length; i++) {
GraphicElement element = workspaceElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] globalElements = getElements(null);
for (int i = 0; i < globalElements.length; i++) {
GraphicElement element = globalElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
} else if (workspaceId != null && sectionId != null & panelId != null) {
//All elements defined for this panel, plus workspace base elements, plus base elements with different id.
Set usedIds = new HashSet();
GraphicElement[] panelElements = getElements(workspaceId, sectionId, panelId);
for (int i = 0; i < panelElements.length; i++) {
GraphicElement element = panelElements[i];
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] sectionElements = getElements(workspaceId, sectionId, null);
for (int i = 0; i < sectionElements.length; i++) {
GraphicElement element = sectionElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] instanceElements = getElements(workspaceId, null, panelId);
for (int i = 0; i < instanceElements.length; i++) {
GraphicElement element = instanceElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] workspaceElements = getElements(workspaceId, null, null);
for (int i = 0; i < workspaceElements.length; i++) {
GraphicElement element = workspaceElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
GraphicElement[] globalElements = getElements(null);
for (int i = 0; i < globalElements.length; i++) {
GraphicElement element = globalElements[i];
if (usedIds.contains(element.getId()))
continue;
usedIds.add(element.getId());
elementsToReturn.add(element);
}
}
GraphicElement[] elementsArray = (GraphicElement[]) elementsToReturn.toArray(new GraphicElement[]{});