/** * Exported the selected item. * * @param item Item to export. * @param eventListener <tt>Event Listener</tt> for the export operation. */ public static void exportSelectedItem( TreeItem item, GetFileNameDialogEventListener eventListener) { if (item == null) { // TODO add message for internationalization purposes Window.alert("Please select the item to export."); return; } if (((Editable) item.getUserObject()).isNew()) { // TODO add message for internationalization purposes Window.alert("Please first save this item."); return; } String name = ""; Object studyItem = item.getUserObject(); if (studyItem instanceof StudyDef) name = ((StudyDef) studyItem).getName(); else if (studyItem instanceof FormDef) name = ((StudyDef) item.getParentItem().getUserObject()).getName() + "-" + ((FormDef) studyItem).getName(); else if (studyItem instanceof FormDefVersion) name = ((StudyDef) item.getParentItem().getParentItem().getUserObject()).getName() + "-" + ((FormDef) item.getParentItem().getUserObject()).getName() + "-" + ((FormDefVersion) studyItem).getName(); name = name.replace(" ", ""); new GetFileNameDialog( eventListener, constants.label_export_as(), constants.label_export(), name) .center(); }
/** * Bind <tt>FormDefVersion</tt> contents. * * @param tree <tt>Tree View</tt> to bind <tt>FormDefVersion</tt> to. * @param item <tt>FormDefVersion</tt> we binding. * @param popup <tt>Popup</tt> to bind to the <tt>Tree View.</tt> * @param editable <tt>Editable</tt> we are checking contents for. */ private static void setFormDefVersionContents( final Tree tree, final TreeItem item, final PopupPanel popup, Editable editable) { if (item == null || !(item.getUserObject() instanceof FormDef)) Window.alert("Please first select the form to import this version into"); else { ((FormDef) item.getUserObject()).addVersion((FormDefVersion) editable); importFormVersion(tree, item, (FormDefVersion) editable, popup); } }
/** * Bind <tt>FormDef</tt> contents. * * @param tree <tt>Tree View</tt> to bind <tt>FormDefVersion</tt> to. * @param item <tt>FormDefVersion</tt> we binding. * @param popup <tt>Popup</tt> to bind to the <tt>Tree View.</tt> * @param editable <tt>Editable</tt> we are checking contents for. */ private static void setFormContents( final Tree tree, final TreeItem item, final PopupPanel popup, Editable editable) { if (item == null || !(item.getUserObject() instanceof StudyDef)) Window.alert("Please first select the study to import this form into"); else { ((StudyDef) item.getUserObject()).addForm((FormDef) editable); importForm(tree, item, (FormDef) editable, popup); } }
/** * Removes the given <tt>Form Def Tree Item</tt> from the Parent. * * @param item <tt>TreeItem</tt> to remove. * @param parent <tt>Parent</tt> of <tt>Tree Item.</tt> */ public static void removeFormDefItem(TreeItem item, TreeItem parent) { Object userObj = item.getUserObject(); Object parentUserObj = parent.getUserObject(); if (userObj instanceof FormDefVersion) { ((FormDef) parentUserObj).removeVersion((FormDefVersion) userObj); ((FormDef) parentUserObj).setDirty(true); ((StudyDef) parent.getParentItem().getUserObject()).setDirty(true); } else if (userObj instanceof FormDef) { ((StudyDef) parentUserObj).removeForm((FormDef) userObj); ((StudyDef) parentUserObj).setDirty(true); } }
/** * Constructs a <code>StudyDef Tree item root</code> to bind other items to. * * @param xDef <code>StudyDef</code> for whom to create root. * @return Constructed <code>Tree Item.</code> */ private static TreeItem constructTreeItem(StudyDef xDef) { TreeItem root = new CompositeTreeItem(new TreeItemWidget(images.note(), xDef.getName(), popup)); if (root.getUserObject() != null) { if (!root.getUserObject().equals(xDef)) { root.setUserObject(xDef); tree.addItem(root); } } else { root.setUserObject(xDef); tree.addItem(root); } return root; }
/* * (non-Javadoc) * * @see * com.google.gwt.user.client.ui.TreeListener#onTreeItemSelected(com.google * .gwt.user.client.ui.TreeItem) */ public void onTreeItemSelected(TreeItem item) { currentlySelected = item; Object u = item.getUserObject(); if (u instanceof VariableSerializable) { VariableSerializable v = (VariableSerializable) u; } }
// TODO to implement @Override public void handleMenuAction(SelectionEvent<TreeItem> event) { TreeItem item = event.getSelectedItem(); if (item.getUserObject().equals(CATEGORY_MENU)) { getModuleListener().connectModule(new CategoryModuleActivity()); } }
/** * Adds a Child Item to the selected item on the <tt>Tree View.</tt> * * <p>If a <tt>Study</tt> is selected, a <tt>Form</tt> will be added, * * <p>If a <tt>Form</tt> is selected, a <tt>Form Version</tt> will be added. * * <p> */ public static void addNewChildItem(Tree tree, List<StudyDef> studies, PopupPanel popup) { String studyName = ""; // Name of study TreeItem item = tree.getSelectedItem(); if (item == null) { addNewItem( null, tree, studies, popup); // Automatically add a new study/form/version to better usability return; } if (item.getUserObject() instanceof StudyDef) { studyName = ((StudyDef) item.getUserObject()).getName(); // set the value of the study from here FormDef formDef = new FormDef( 0, studyName + " Form" + (item.getChildCount() + 1), (StudyDef) item.getUserObject()); formDef.setCreator(Context.getAuthenticatedUser()); formDef.setDateCreated(new Date()); formDef.setDirty(true); item = addImageItem(item, formDef.getName(), images.drafts(), formDef, null, popup); ((StudyDef) item.getParentItem().getUserObject()).addForm(formDef); tree.setSelectedItem(item); item.getParentItem().setState(true); // Automatically add a new form version addNewChildItem(tree, studies, popup); } else if (item.getUserObject() instanceof FormDef) { FormDefVersion formDefVersion = new FormDefVersion(0, "v" + (item.getChildCount() + 1), (FormDef) item.getUserObject()); formDefVersion.setCreator(Context.getAuthenticatedUser()); formDefVersion.setDateCreated(new Date()); formDefVersion.getFormDef().turnOffOtherDefaults(formDefVersion); formDefVersion.setDirty(true); item = addImageItem( item, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup); ((FormDef) item.getParentItem().getUserObject()).addVersion(formDefVersion); tree.setSelectedItem(item); item.getParentItem().setState(true); } else addNewItem(null, tree, studies, popup); }
/** * Evaluates security to action ( to prevent not permission access to folder destination ) * * @param item The tree item */ public void evaluateSecurityToAction(TreeItem item) { // Enables or disables move button if ((((GWTFolder) item.getUserObject()).getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) { Main.get().activeFolderTree.folderSelectPopup.enable(true); } else { Main.get().activeFolderTree.folderSelectPopup.enable(false); } }
@Override public void onOpen(OpenEvent<TreeItem> event) { TreeItem item = event.getTarget(); currentlySelected = item; if (item.getChild(0).getText().equals(DatasetWidget.LOADING)) { CategorySerializable cat = (CategorySerializable) item.getUserObject(); Util.getRPCService().getCategories(cat.getID(), null, categoryCallback); } }
public void onOpen(OpenEvent<TreeItem> event) { TreeItem node = event.getTarget(); Object userObject = node.getUserObject(); if (userObject != null && userObject instanceof String && "rootNode".equals((String) userObject)) { node.removeItems(); setupPackageNode(node); } }
/** * Adds a new Item according to selected item on the <tt>Tree View.</tt> * * <p>If a <Study</tt> is selected, a new <tt>Study</tt> will be added. * * <p>If a <tt>Form</tt> is selected, a new <tt>Form</tt> will be added. * * <p>If a <tt>Form Version</tt> is selected, a new <tt>Form Version</tt> will be added. */ public static void addNewItem(String xForm, Tree tree, List<StudyDef> studies, PopupPanel popup) { TreeItem item = tree.getSelectedItem(); if (item == null || item.getUserObject() instanceof StudyDef) { StudyDef studyDef = new StudyDef(0, "New Study" + (tree.getItemCount() + 1)); studyDef.setCreator(Context.getAuthenticatedUser()); studyDef.setDateCreated(new Date()); studyDef.setDirty(true); TreeItem root = new CompositeTreeItem(new TreeItemWidget(images.note(), studyDef.getName(), popup)); root.setUserObject(studyDef); tree.addItem(root); studies.add(studyDef); tree.setSelectedItem(root); // Automatically add a new form addNewChildItem(tree, studies, popup); } else if (item.getUserObject() instanceof FormDef) { TreeItem parent = item.getParentItem(); FormDef formDef = new FormDef( 0, "New Form" + (parent.getChildCount() + 1), (StudyDef) parent.getUserObject()); formDef.setCreator(Context.getAuthenticatedUser()); formDef.setDateCreated(new Date()); formDef.setDirty(true); item = addImageItem(parent, formDef.getName(), images.drafts(), formDef, null, popup); ((StudyDef) parent.getUserObject()).addForm(formDef); tree.setSelectedItem(item); parent.setState(true); // Automatically add a new form version addNewChildItem(tree, studies, popup); } else if (item.getUserObject() instanceof FormDefVersion) { TreeItem parent = item.getParentItem(); FormDefVersion formDefVersion = new FormDefVersion( 0, "v" + (parent.getChildCount() + 1), (FormDef) parent.getUserObject()); formDefVersion.setCreator(Context.getAuthenticatedUser()); formDefVersion.setDateCreated(new Date()); formDefVersion.getFormDef().turnOffOtherDefaults(formDefVersion); formDefVersion.setDirty(true); if (xForm != null) formDefVersion.setXform(xForm); item = addImageItem( parent, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup); ((FormDef) parent.getUserObject()).addVersion(formDefVersion); tree.setSelectedItem(item); parent.setState(true); } }
public void onSuccess(List<GWTFolder> result) { boolean directAdd = true; // If has no childs directly add values is permited if (actualItem.getChildCount() > 0) { directAdd = false; // to prevent remote folder remove it disables all tree branch // items and after sequentially activate hideAllBranch(actualItem); } // On refreshing not refreshed the actual item values but must // ensure that has childs value is consistent if (result.isEmpty()) { ((GWTFolder) actualItem.getUserObject()).setHasChildren(false); } else { ((GWTFolder) actualItem.getUserObject()).setHasChildren(true); } // Ads folders childs if exists for (Iterator<GWTFolder> it = result.iterator(); it.hasNext(); ) { GWTFolder folder = it.next(); TreeItem folderItem = new TreeItem(folder.getName()); folderItem.setUserObject(folder); folderItem.setStyleName("okm-TreeItem"); // If has no childs directly add values is permited, else // evalues each node to refresh, remove or add if (directAdd) { evaluesFolderIcon(folderItem); actualItem.addItem(folderItem); } else { // sequentially activate items and refreshes values addFolder(actualItem, folderItem); } } actualItem.setState(true); evaluesFolderIcon(actualItem); }
/** * Fired when an option is selected on the <tt>FormVersionOpenDialogListener.</tt> * * @param option the selected option. * @param tree <tt>Tree View</tt> we checking items from. * @param item <tt>Tree Item</tt> we checking. * @param eventBus <tt>ItemSelectionListener</tt> for the data check operation. * @param popup <tt>Popup</tt> for the <tt>Tree View.</tt> */ public static void onOptionSelected( int option, Tree tree, TreeItem item, EventBus eventBus, PopupPanel popup) { if (option == 0) { // Create new form verson if (item.getUserObject() instanceof FormDefVersion) { FormDefVersion copyVersion = (FormDefVersion) item.getUserObject(); String xForm = copyVersion.getXform(); addNewItem(xForm, tree, Context.getStudies(), popup); } } else if (option == 1) { // Open the dialog as read only final Object userObject = tree.getSelectedItem().getUserObject(); // ((StudyView)eventBus).designItem(true, tree.getSelectedItem().getUserObject()); if (userObject instanceof FormDefVersion) eventBus.fireEvent(new DesignFormEvent((FormDefVersion) userObject)); } else if (option == 2) { // Cancel option return; } else { // ((StudyView)eventBus).designItem(false, tree.getSelectedItem().getUserObject()); final Object userObject = tree.getSelectedItem().getUserObject(); if (userObject instanceof FormDefVersion) eventBus.fireEvent(new DesignFormEvent((FormDefVersion) userObject, true)); } }
/** * Imports a Form Version. * * @param tree * @param parent * @param formDefVersion * @param popup */ public static void importFormVersion( Tree tree, TreeItem parent, FormDefVersion formDefVersion, PopupPanel popup) { formDefVersion.setFormDef((FormDef) parent.getUserObject()); formDefVersion.setCreator(Context.getAuthenticatedUser()); formDefVersion.setDateCreated(new Date()); formDefVersion.setDirty(true); TreeItem item = addImageItem( parent, formDefVersion.getName(), images.markRead(), formDefVersion, null, popup); tree.setSelectedItem(item); item.getParentItem().setState(true); }
/** * Prevents folder inconsistences between server ( multi user deletes folder ) and tree nodes * drawn * * @param item The tree node */ public void preventFolderInconsitences(TreeItem item) { GWTFolder folderItem = (GWTFolder) item.getUserObject(); // Case that must remove all items node if (item.getChildCount() > 0 && !folderItem.isHasChildren()) { while (item.getChildCount() > 0) { item.getChild(0).remove(); } } if (item.getChildCount() < 1 && !folderItem.isHasChildren()) { folderItem.setHasChildren(false); } }
public void onSelection(SelectionEvent<TreeItem> event) { TreeItem item = event.getSelectedItem(); if (item.getUserObject() instanceof Object[]) { Object[] o = (Object[]) item.getUserObject(); final String snapName = ((SnapshotInfo) o[0]).name; PackageConfigData conf = (PackageConfigData) o[1]; RepositoryServiceFactory.getPackageService() .listSnapshots( conf.name, new GenericCallback<SnapshotInfo[]>() { public void onSuccess(SnapshotInfo[] a) { for (SnapshotInfo snap : a) { if (snap.name.equals(snapName)) { TabOpener opener = TabOpener.getInstance(); opener.openSnapshot(snap); return; } } } }); } }
private void setSelectedItem(String section, Iterator<TreeItem> iterator) { if (iterator == null) { if (tree.getSelectedItem() != null) { if (tree.getSelectedItem().getUserObject().equals(section)) return; } iterator = tree.treeItemIterator(); } while (iterator.hasNext()) { TreeItem item = iterator.next(); if (item.getUserObject().equals(section)) { tree.setSelectedItem(item, false); return; } } }
@Override public void onSelection(SelectionEvent<TreeItem> event) { TreeItem item = event.getSelectedItem(); currentlySelected = item; TreeItem child = item.getChild(0); if (child != null && child.getText().equals(DatasetWidget.LOADING)) { CategorySerializable cat = (CategorySerializable) item.getUserObject(); Util.getRPCService().getCategories(cat.getID(), null, categoryCallback); } // Open the item. Work around double firing bug. // http://code.google.com/p/google-web-toolkit/issues/detail?id=3660&q=Tree%20selection&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars TreeItem selItem = event.getSelectedItem(); TreeItem parent = selItem.getParentItem(); selItem.getTree().setSelectedItem(parent, false); // null is ok if (parent != null) parent.setSelected(false); // not compulsory selItem.setState(!selItem.getState(), false); }
/** * Imports a <tt>FormDef.</tt> * * @param tree <tt>Tree View</tt> we importing too. * @param parent <tt>FormDef</tt> parent. Should be a <tt>StudyDef.</tt> * @param formDef <tt>FormDef</tt> we are importing. * @param popup <tt>Popup</tt> for the <tt>Tree View.</tt> */ public static void importForm(Tree tree, TreeItem parent, FormDef formDef, PopupPanel popup) { formDef.setStudy((StudyDef) parent.getUserObject()); formDef.setCreator(Context.getAuthenticatedUser()); formDef.setDateCreated(new Date()); formDef.setDirty(true); TreeItem item = addImageItem(parent, formDef.getName(), images.drafts(), formDef, null, popup); tree.setSelectedItem(item); item.getParentItem().setState(true); TreeItem versionParent = item; List<FormDefVersion> versions = formDef.getVersions(); if (versions != null) { for (FormDefVersion formDefVersion : versions) importFormVersion(tree, versionParent, formDefVersion, popup); } }
/** * Evalues actual folder icon to prevent other user interaction with the same folder this ensures * icon and object hasChildsValue are consistent */ public void evaluesFolderIcon(TreeItem item) { GWTFolder folderItem = (GWTFolder) item.getUserObject(); preventFolderInconsitences(item); // Looks if must change icon on parent if now has no childs and properties with user security // atention if ((folderItem.getPermissions() & GWTPermission.WRITE) == GWTPermission.WRITE) { if (folderItem.isHasChildren()) { item.setHTML(Util.imageItemHTML("img/menuitem_childs.gif", folderItem.getName(), "top")); } else { item.setHTML(Util.imageItemHTML("img/menuitem_empty.gif", folderItem.getName(), "top")); } } else { if (folderItem.isHasChildren()) { item.setHTML(Util.imageItemHTML("img/menuitem_childs_ro.gif", folderItem.getName(), "top")); } else { item.setHTML(Util.imageItemHTML("img/menuitem_empty_ro.gif", folderItem.getName(), "top")); } } }
// Show the associated widget in the deck panel public void onSelection(SelectionEvent<TreeItem> event) { TreeItem node = event.getSelectedItem(); Object userObject = node.getUserObject(); TabOpener opener = TabOpener.getInstance(); if (userObject != null) { if (userObject instanceof PackageConfigData && !((PackageConfigData) userObject).isGlobal()) { PackageConfigData pc = (PackageConfigData) userObject; RulePackageSelector.currentlySelectedPackage = pc.name; String uuid = pc.uuid; opener.openPackageEditor( uuid, new Command() { public void execute() { // refresh the package tree. refreshTree(); } }); } else if (userObject instanceof String[]) { final String[] formats = (String[]) userObject; final PackageConfigData packageConfigData = (PackageConfigData) node.getParentItem().getUserObject(); RulePackageSelector.currentlySelectedPackage = packageConfigData.name; String key = key(formats, packageConfigData); opener.openPackageViewAssets( packageConfigData.uuid, packageConfigData.name, key, formats.length == 0 ? null : Arrays.asList(formats), formats.length == 0 ? Boolean.TRUE : null, node.getText()); } else if (userObject instanceof String) { // Ignore, there is no click event for this. } else { throw new IllegalArgumentException("The userObject (" + userObject + ") is not supported."); } } }
public void onOpen(OpenEvent<TreeItem> event) { final TreeItem node = event.getTarget(); if (ExplorerNodeConfig.PACKAGE_SNAPSHOTS.equals(itemWidgets.get(node))) { return; } final PackageConfigData conf = (PackageConfigData) node.getUserObject(); if (conf != null) { RepositoryServiceFactory.getPackageService() .listSnapshots( conf.name, new GenericCallback<SnapshotInfo[]>() { public void onSuccess(SnapshotInfo[] snaps) { node.removeItems(); for (final SnapshotInfo snapInfo : snaps) { TreeItem snap = new TreeItem(snapInfo.name); // snap.setTooltip(snapInfo.comment); snap.setUserObject(new Object[] {snapInfo, conf}); node.addItem(snap); } } }); } }
/** * Adds folders to actual item if not exists or refreshes it values * * @param actualItem The actual item active * @param newItem New item to be added, or refreshed */ public void addFolder(TreeItem actualItem, TreeItem newItem) { int i = 0; boolean found = false; int count = actualItem.getChildCount(); GWTFolder folder; GWTFolder newFolder = (GWTFolder) newItem.getUserObject(); String folderPath = newFolder.getPath(); for (i = 0; i < count; i++) { folder = (GWTFolder) actualItem.getChild(i).getUserObject(); // If item is found actualizate values if ((folder).getPath().equals(folderPath)) { found = true; actualItem.getChild(i).setVisible(true); actualItem.getChild(i).setUserObject(newFolder); evaluesFolderIcon(actualItem.getChild(i)); } } if (!found) { evaluesFolderIcon(newItem); actualItem.addItem(newItem); } }
@SuppressWarnings("unchecked") public void populateFilesList( SolutionBrowserPerspective perspective, SolutionTree solutionTree, TreeItem item) { filesList.clear(); ArrayList<Element> files = (ArrayList<Element>) item.getUserObject(); // let's sort this list based on localized name Collections.sort( files, new Comparator<Element>() { public int compare(Element o1, Element o2) { String name1 = o1.getAttribute("localized-name"); // $NON-NLS-1$ String name2 = o2.getAttribute("localized-name"); // $NON-NLS-1$ return name1.compareTo(name2); } }); if (files != null) { int rowCounter = 0; for (int i = 0; i < files.size(); i++) { Element fileElement = files.get(i); if ("false".equals(fileElement.getAttribute("isDirectory"))) { // $NON-NLS-1$ //$NON-NLS-2$ String name = fileElement.getAttribute("name"); // $NON-NLS-1$ String solution = solutionTree.getSolution(); String path = solutionTree.getPath(); String lastModifiedDateStr = fileElement.getAttribute("lastModifiedDate"); // $NON-NLS-1$ String url = fileElement.getAttribute("url"); // $NON-NLS-1$ ContentTypePlugin plugin = PluginOptionsHelper.getContentTypePlugin(name); String icon = null; if (plugin != null) { icon = plugin.getFileIcon(); } String localizedName = fileElement.getAttribute("localized-name"); String description = fileElement.getAttribute("description"); String tooltip = localizedName; if (solutionTree.isUseDescriptionsForTooltip() && !StringUtils.isEmpty(description)) { tooltip = description; } final FileItem fileLabel = new FileItem( name, localizedName, tooltip, solution, path, //$NON-NLS-1$ lastModifiedDateStr, url, this, PluginOptionsHelper.getEnabledOptions(name), toolbar.getSupportsACLs(), icon); // BISERVER-2317: Request for more IDs for Mantle UI elements // set element id as the filename fileLabel.getElement().setId("file-" + name); // $NON-NLS-1$ fileLabel.addFileSelectionChangedListener(toolbar); fileLabel.setWidth("100%"); // $NON-NLS-1$ try { perspective.getDragController().makeDraggable(fileLabel); } catch (Exception e) { Throwable throwable = e; String text = "Uncaught exception: "; while (throwable != null) { StackTraceElement[] stackTraceElements = throwable.getStackTrace(); text += throwable.toString() + "\n"; for (int ii = 0; ii < stackTraceElements.length; ii++) { text += " at " + stackTraceElements[ii] + "\n"; } throwable = throwable.getCause(); if (throwable != null) { text += "Caused by: "; } } DialogBox dialogBox = new DialogBox(true); DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF"); System.err.print(text); text = text.replaceAll(" ", " "); dialogBox.setHTML("<pre>" + text + "</pre>"); dialogBox.center(); } filesList.setWidget(rowCounter++, 0, fileLabel); if (selectedFileItem != null && selectedFileItem.getFullPath().equals(fileLabel.getFullPath())) { fileLabel.setStyleName("fileLabelSelected"); // $NON-NLS-1$ selectedFileItem = fileLabel; } else { fileLabel.setStyleName("fileLabel"); // $NON-NLS-1$ } } } } }
public Object getCurrentlySelected() { return currentlySelected.getUserObject(); }
/** * Gets the actual path of the selected directory tree * * @return The actual path of selected directory */ public String getActualPath() { return ((GWTFolder) actualItem.getUserObject()).getPath(); }
/** Refresh the tree node */ public void refresh(boolean reset) { String path = ((GWTFolder) actualItem.getUserObject()).getPath(); getChilds(path); }