Search in sources :

Example 11 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrPropertiesView method refreshContent.

void refreshContent() {
    final Object input = viewer.getInput();
    if (input != null && input instanceof JcrNode) {
        JcrNode jcrnode = (JcrNode) input;
        SyncDir syncDir = jcrnode.getSyncDir();
        JcrNode newnode = syncDir.getNode(jcrnode.getJcrPath());
        if (newnode != null) {
            viewer.setInput(newnode);
            if (lastEditedNewPropertyName != null) {
                for (int i = 0; ; i++) {
                    Object element = viewer.getElementAt(i);
                    if (element == null) {
                        break;
                    }
                    final IPropertyDescriptor pd = (IPropertyDescriptor) element;
                    Map.Entry<String, Object> me = (Entry<String, Object>) pd.getId();
                    String key = me.getKey();
                    if (lastEditedNewPropertyName.equals(key)) {
                        // set the selection to this one
                        final int column;
                        if (lastEditedColumnId == ColumnId.NAME) {
                            column = 0;
                        } else if (lastEditedColumnId == ColumnId.TYPE) {
                            column = 1;
                        } else if (lastEditedColumnId == ColumnId.VALUE) {
                            column = 2;
                        } else if (lastEditedColumnId == ColumnId.MULTIPLE) {
                            column = 5;
                        } else {
                            throw new IllegalStateException("Unknown columnId=" + lastEditedColumnId);
                        }
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    // edit
                                    viewer.editElement(pd, column);
                                    // and cancel immediately - to get the selection right
                                    viewer.cancelEditing();
                                } catch (Exception e) {
                                    Activator.getDefault().getPluginLogger().error("Exception occured on edit/cancel: " + e, e);
                                }
                            }
                        });
                        break;
                    }
                }
            }
        }
    }
}
Also used : SyncDir(org.apache.sling.ide.eclipse.ui.nav.model.SyncDir) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) Entry(java.util.Map.Entry) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) Map(java.util.Map)

Example 12 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrCellLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    int index = cell.getColumnIndex();
    if (!isNewRow(cell)) {
        if (canEdit(cell)) {
            cell.setForeground(normalColor);
        } else {
            cell.setForeground(greyColor);
        }
    }
    if (index == 0) {
        updateName(cell);
        return;
    } else if (index == 1) {
        final Object element = cell.getElement();
        if (element instanceof NewRow) {
            NewRow newRow = (NewRow) element;
            int propertyType = newRow.getType();
            String type = PropertyType.nameFromValue(propertyType);
            cell.setText(type);
        } else if (element instanceof IPropertyDescriptor) {
            IPropertyDescriptor pd = (IPropertyDescriptor) element;
            JcrNode jcrNode = (JcrNode) viewer.getInput();
            Map.Entry me = (Entry) pd.getId();
            final String propertyName = String.valueOf(me.getKey());
            int propertyType = jcrNode.getPropertyType(propertyName);
            if (propertyType <= -1 || propertyType == PropertyType.UNDEFINED) {
                cell.setText("");
            } else {
                final JcrProperty property = jcrNode.getProperty(propertyName);
                String type = PropertyType.nameFromValue(propertyType);
                if (property != null && property.isMultiple()) {
                    type = type + "[]";
                }
                cell.setText(type);
            }
        } else {
            cell.setText("");
        }
        return;
    } else if (index == 2) {
        updateValue(cell);
        return;
    } else {
        final Object element = cell.getElement();
        if (element instanceof NewRow) {
            NewRow newRow = (NewRow) element;
            cell.setText("");
        } else if (element instanceof IPropertyDescriptor) {
            IPropertyDescriptor pd = (IPropertyDescriptor) element;
            JcrNode jcrNode = (JcrNode) viewer.getInput();
            Map.Entry me = (Entry) pd.getId();
            PropertyDefinition prd = jcrNode.getPropertyDefinition(String.valueOf(me.getKey()));
            if (index == 3) {
                // protected
                if (prd != null) {
                    cell.setText(String.valueOf(prd.isProtected()));
                } else {
                    cell.setText("false");
                }
            } else if (index == 4) {
                // mandatory
                if (prd != null) {
                    cell.setText(String.valueOf(prd.isMandatory()));
                } else {
                    cell.setText("false");
                }
            } else if (index == 5) {
                // multiple
                if (prd != null) {
                    cell.setText(String.valueOf(prd.isMultiple()));
                } else {
                    cell.setText(String.valueOf(jcrNode.getProperty(String.valueOf(me.getKey())).isMultiple()));
                }
            } else if (index == 6) {
                // auto creatd
                if (prd != null) {
                    cell.setText(String.valueOf(prd.isAutoCreated()));
                } else {
                    cell.setText("false");
                }
            } else {
                cell.setText("n/a");
                return;
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) JcrProperty(org.apache.sling.ide.eclipse.ui.nav.model.JcrProperty) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) Map(java.util.Map) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 13 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrEditingSupport method handleNewRowUpdate.

void handleNewRowUpdate(NewRow newRow) {
    if (newRow.isComplete()) {
        tableViewer.remove(newRow);
        final JcrNode jcrNode = (JcrNode) tableViewer.getInput();
        final Integer type = newRow.getType();
        String encodeValueAsString = PropertyTypeSupport.encodeValueAsString(newRow.getValue(), type);
        if (type != PropertyType.STRING && type != PropertyType.NAME) {
            encodeValueAsString = "{" + PropertyType.nameFromValue(type) + "}" + encodeValueAsString;
        }
        final String propertyName = String.valueOf(newRow.getName());
        jcrNode.addProperty(propertyName, encodeValueAsString);
        view.refreshContent();
    } else {
        tableViewer.update(newRow, null);
    }
}
Also used : JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode)

Example 14 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrPropertiesView method createPartControl.

/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
public void createPartControl(Composite parent) {
    SyncDirManager.registerUpdateListener(new UpdateHandler() {

        @Override
        public void syncDirUpdated(SyncDir syncDir) {
            refreshContent();
        }
    });
    mainControl = new Composite(parent, SWT.NONE);
    final GridLayout gridLayout = new GridLayout(1, true);
    mainControl.setLayout(gridLayout);
    if (getViewSite() != null) {
        titleLabel = new Label(mainControl, SWT.WRAP);
        titleLabel.setText("");
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        titleLabel.setLayoutData(data);
        Label horizontalLine = new Label(mainControl, SWT.SEPARATOR | SWT.HORIZONTAL);
        data = new GridData(GridData.FILL_HORIZONTAL);
        horizontalLine.setLayoutData(data);
    }
    Font font;
    if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
        FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
        /* title font is 2pt larger than that used in the tabs. */
        fontData[0].setHeight(fontData[0].getHeight() + 2);
        JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
    }
    font = JFaceResources.getFont(TITLE_FONT);
    if (titleLabel != null) {
        titleLabel.setFont(font);
    }
    Composite tableParent = new Composite(mainControl, SWT.NONE);
    //        tableParent.setBackground(new Color(Display.getDefault(), 100,20,180));
    GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    // shrink to min - table settings will resize to correct ratios
    tableLayoutData.widthHint = 1;
    tableLayoutData.heightHint = SWT.DEFAULT;
    tableParent.setLayoutData(tableLayoutData);
    TableColumnLayout tableLayout = new TableColumnLayout() {

        @Override
        protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
            Point p = super.computeSize(composite, wHint, hHint, flushCache);
            return new Point(p.x, p.y);
        }
    };
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION);
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer), new CellNavigationStrategy());
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            resetLastValueEdited();
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
    TableViewerEditor.create(viewer, focusCellManager, actSupport, features);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    deleteAction.setEnabled(false);
                } else {
                    deleteAction.setEnabled(true);
                }
            } else {
                deleteAction.setEnabled(false);
            }
        }
    });
    CellLabelProvider clp = new JcrCellLabelProvider(viewer);
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Name");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(200);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(30, 140));
    final TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Type");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(300);
    column1.setLabelProvider(clp);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(10, 80));
    final TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
    column2.getColumn().setText("Value");
    column2.getColumn().setResizable(true);
    column2.getColumn().setWidth(300);
    tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(70, 220));
    final TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
    column3.getColumn().setText("Protected");
    column3.getColumn().setResizable(true);
    column3.getColumn().setWidth(300);
    column3.setLabelProvider(clp);
    tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(5, 57));
    final TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
    column4.getColumn().setText("Mandatory");
    column4.getColumn().setResizable(true);
    column4.getColumn().setWidth(300);
    column4.setLabelProvider(clp);
    tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(5, 62));
    final TableViewerColumn column5 = new TableViewerColumn(viewer, SWT.NONE);
    column5.getColumn().setText("Multiple");
    column5.getColumn().setResizable(true);
    column5.getColumn().setWidth(300);
    column5.setLabelProvider(clp);
    tableLayout.setColumnData(column5.getColumn(), new ColumnWeightData(5, 82));
    final TableViewerColumn column6 = new TableViewerColumn(viewer, SWT.NONE);
    column6.getColumn().setText("Auto Created");
    column6.getColumn().setResizable(true);
    column6.getColumn().setWidth(300);
    column6.setLabelProvider(clp);
    tableLayout.setColumnData(column6.getColumn(), new ColumnWeightData(5, 77));
    column0.setLabelProvider(clp);
    column0.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.NAME));
    column1.setLabelProvider(clp);
    column1.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.TYPE));
    column2.setLabelProvider(clp);
    column2.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.VALUE));
    column5.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.MULTIPLE));
    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.sling.ide.eclipse-ui.viewer");
    makeActions();
    hookContextMenu();
    hookDoubleClickAction();
    contributeToActionBars();
    listener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                Object firstElem = iss.getFirstElement();
                if (firstElem instanceof JcrNode) {
                    JcrNode jcrNode = (JcrNode) firstElem;
                    setInput(jcrNode);
                    return;
                }
            }
        }
    };
    if (getViewSite() != null) {
        getViewSite().getPage().addSelectionListener(listener);
        final ISelection selection = getViewSite().getPage().getSelection();
        Display.getCurrent().asyncExec(new Runnable() {

            @Override
            public void run() {
                listener.selectionChanged(null, selection);
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Label(org.eclipse.swt.widgets.Label) SyncDir(org.apache.sling.ide.eclipse.ui.nav.model.SyncDir) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Font(org.eclipse.swt.graphics.Font) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) UpdateHandler(org.apache.sling.ide.eclipse.ui.nav.model.UpdateHandler) Composite(org.eclipse.swt.widgets.Composite) FontData(org.eclipse.swt.graphics.FontData) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Point(org.eclipse.swt.graphics.Point) CellNavigationStrategy(org.eclipse.jface.viewers.CellNavigationStrategy) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 15 with JcrNode

use of org.apache.sling.ide.eclipse.ui.nav.model.JcrNode in project sling by apache.

the class JcrNodeRenameHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelection(event);
    JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
    if (node == null) {
        return null;
    }
    Shell shell = HandlerUtil.getActiveShell(event);
    InputDialog id = new InputDialog(shell, "Change Node Name", "Enter new name for node '" + node.getDescription() + "':", node.getLabel(), NodeNameValidator.INSTANCE);
    if (id.open() == IStatus.OK) {
        node.rename(id.getValue());
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) InputDialog(org.eclipse.jface.dialogs.InputDialog) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

JcrNode (org.apache.sling.ide.eclipse.ui.nav.model.JcrNode)27 ISelection (org.eclipse.jface.viewers.ISelection)10 Test (org.junit.Test)8 SyncDir (org.apache.sling.ide.eclipse.ui.nav.model.SyncDir)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 JcrContentContentProvider (org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider)3 Shell (org.eclipse.swt.widgets.Shell)3 PartInitException (org.eclipse.ui.PartInitException)3 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)3 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Point (org.eclipse.swt.graphics.Point)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NodeType (javax.jcr.nodetype.NodeType)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 JcrProperty (org.apache.sling.ide.eclipse.ui.nav.model.JcrProperty)1