use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.
the class JcrNodeCreationTest method createUnstructuredNodeWithSpecialName.
@Test
public void createUnstructuredNodeWithSpecialName() throws Exception {
JcrNode contentNode = syncDirNode.getNode("/content/test-root");
contentNode.createChild("sling:stuff", "nt:unstructured");
assertThat(projectRule.getProject(), hasFile("/jcr_root/content/test-root/_sling_stuff/.content.xml"));
}
use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.
the class JcrContentContentProviderTest method assertIsNavigableAndHasNoChildren.
/**
* Asserts that the specified <tt>nodePath</tt> is reachable from the <tt>startNode</tt>
*
* <p>It further asserts that there are no children beyond the <tt>nodePath</tt>, i.e. it
* is and endpoint</p>
*
* @param startNode the node to start from
* @param nodePath the path that is reachable and an endpoint
*/
private void assertIsNavigableAndHasNoChildren(SyncDir startNode, String nodePath) {
JcrContentContentProvider contentProvider = new JcrContentContentProvider();
if (nodePath.charAt(0) == '/') {
nodePath = nodePath.substring(1);
}
String[] pathElements = nodePath.split("/");
JcrNode current = startNode;
segments: for (int i = 0; i < pathElements.length; i++) {
String expectedChildName = pathElements[i];
Object[] children = contentProvider.getChildren(current);
for (Object child : children) {
JcrNode childNode = (JcrNode) child;
// childNode.getName() does not seem to be usable here, so relying on the path
String childName = PathUtil.getName(childNode.getJcrPath());
if (childName.equals(expectedChildName)) {
current = childNode;
continue segments;
}
}
fail("Unable to navigate to '" + nodePath + "'. " + " No child named '" + expectedChildName + "'found for node at " + current.getJcrPath() + ", children: " + Arrays.toString(children));
}
Object[] children = contentProvider.getChildren(current);
if (children.length != 0) {
fail("Unexpected children for node at '" + current.getJcrPath() + "' : " + Arrays.toString(children));
}
}
use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.
the class JcrPropertiesView method makeActions.
private void makeActions() {
insertAction = new Action() {
public void run() {
NewRow newRow = new NewRow();
viewer.add(newRow);
viewer.getTable().setTopIndex(viewer.getTable().getItemCount());
viewer.getTable().select(viewer.getTable().getItemCount() - 1);
viewer.editElement(newRow, 0);
}
};
insertAction.setText("Insert");
insertAction.setToolTipText("Insert a property");
insertAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
deleteAction = new Action() {
public void run() {
if (viewer.getSelection().isEmpty()) {
return;
}
ISelection sel = viewer.getSelection();
if (sel instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) sel;
Object elem = iss.getFirstElement();
if (elem instanceof IPropertyDescriptor) {
IPropertyDescriptor pd = (IPropertyDescriptor) elem;
JcrNode jcrnode = (JcrNode) viewer.getInput();
jcrnode.deleteProperty(pd.getDisplayName());
refreshContent();
}
}
}
};
deleteAction.setText("Delete");
deleteAction.setToolTipText("Delete a proeprty");
deleteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
doubleClickAction = new Action() {
public void run() {
//TODO doesn't do anything currently..
ISelection selection = viewer.getSelection();
// Object obj = ((IStructuredSelection)selection).getFirstElement();
// showMessage("Double-click detected on "+obj.toString());
}
};
showInEditorAction = new Action() {
public void run() {
JcrNode node = (JcrNode) viewer.getInput();
final IFile file = node.getFileForEditor();
if (file != null) {
try {
IDE.openEditor(getPage(), file, true);
} catch (PartInitException e) {
e.printStackTrace(System.out);
}
}
}
};
showInEditorAction.setText("Show in editor");
showInEditorAction.setToolTipText("Show underlying vault file in editor");
showInEditorAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
if (getViewSite() != null) {
pinAction = new Action("pin to selection", IAction.AS_CHECK_BOX) {
public void run() {
if (!pinAction.isChecked()) {
// unpin
setContentDescription("");
setInput(lastInput);
} else {
setContentDescription("[pinned]");
}
// toggle state of syncedAction accordingly
if (synchedAction != null) {
synchedAction.setEnabled(!pinAction.isChecked());
}
}
};
pinAction.setText("Pin to selection");
pinAction.setToolTipText("Pin this property view to the current selection");
pinAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR));
pinAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR_DISABLED));
pinAction.setChecked(false);
synchedAction = new Action("Link with Editor and selection", IAction.AS_CHECK_BOX) {
public void run() {
// toggle state of pinAction accordingly
pinAction.setEnabled(!synchedAction.isChecked());
}
};
synchedAction.setText("Link with Editor and selection");
synchedAction.setToolTipText("Link with Editor and selection");
synchedAction.setImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED));
synchedAction.setDisabledImageDescriptor(WorkbenchImages.getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED_DISABLED));
synchedAction.setChecked(true);
}
}
use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.
the class PackageExplorerOpenActionProvider method fillActionBars.
@Override
public void fillActionBars(IActionBars actionBars) {
if (fInViewPart) {
ISelection selection = treeViewer.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
if (iss.getFirstElement() instanceof JcrNode) {
final JcrNode node = (JcrNode) iss.getFirstElement();
final IFile file = node.getFileForEditor();
if (file != null) {
actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, new OpenFileAction(getActivePage()) {
@Override
public void run() {
try {
IDE.openEditor(getActivePage(), file, true);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
return;
}
}
// fOpenGroup.fillActionBars(actionBars);
//
// if (fOpenAndExpand == null && fOpenGroup.getOpenAction().isEnabled()) // TODO: is not updated!
// actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction());
// else if (fOpenAndExpand != null && fOpenAndExpand.isEnabled())
}
actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, action);
}
use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.
the class JcrContentLabelProvider method getImage.
@Override
public Image getImage(Object element) {
if (element instanceof JcrNode) {
JcrNode jcrNode = (JcrNode) element;
long start = System.currentTimeMillis();
Image image = jcrNode.getImage();
// add problems marker overlay for errors (element must be the underlying IResource)
image = problemsLabelDecorator.decorateImage(image, ((JcrNode) element).getResource());
long end = System.currentTimeMillis();
Activator.getDefault().getPluginLogger().tracePerformance("getImage for node at {0}", (end - start), jcrNode.getJcrPath());
return image;
} else {
// fallback to default
return null;
}
}
Aggregations