use of org.eclipse.ui.views.properties.IPropertyDescriptor in project meclipse by flaper87.
the class DBObjectPropertySource method getPropertyDescriptors.
public IPropertyDescriptor[] getPropertyDescriptors() {
IPropertyDescriptor[] returnVal = new IPropertyDescriptor[dbObj.keySet().size()];
int counter = 0;
for (String propKey : dbObj.keySet()) {
returnVal[counter] = new PropertyDescriptor(propKey, propKey);
counter++;
}
return returnVal;
}
use of org.eclipse.ui.views.properties.IPropertyDescriptor in project sling by apache.
the class ModifiableProperties method getPropertyDescriptors.
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
final Map<String, IPropertyDescriptor> conversionMap = new HashMap<>();
for (Entry<String, String> entry : properties.entrySet()) {
TextPropertyDescriptor pd = new JcrTextPropertyDescriptor(entry, entry.getKey());
conversionMap.put(entry.getKey(), pd);
}
final List<String> propertiesOrderCopy = new LinkedList<>(propertiesOrder);
final String jcrPrimaryType = "jcr:primaryType";
if (!properties.containsKey(jcrPrimaryType)) {
Map<String, String> pseudoMap = new HashMap<>();
pseudoMap.put(jcrPrimaryType, node.getPrimaryType());
final TextPropertyDescriptor pseudoPd = new JcrTextPropertyDescriptor(pseudoMap.entrySet().iterator().next(), jcrPrimaryType);
propertiesOrderCopy.add(0, jcrPrimaryType);
conversionMap.put(jcrPrimaryType, pseudoPd);
}
IPropertyDescriptor[] result = new IPropertyDescriptor[conversionMap.size()];
for (int i = 0; i < result.length; i++) {
String aPropertyName = propertiesOrderCopy.get(i);
result[i] = conversionMap.get(aPropertyName);
}
return result;
}
use of org.eclipse.ui.views.properties.IPropertyDescriptor 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;
}
}
}
}
}
}
use of org.eclipse.ui.views.properties.IPropertyDescriptor 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;
}
}
}
}
use of org.eclipse.ui.views.properties.IPropertyDescriptor 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);
}
}
Aggregations