use of org.apache.sling.ide.transport.Repository in project sling by apache.
the class JcrNewNodeHandler 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);
if (!node.canCreateChild()) {
MessageDialog.openInformation(shell, "Cannot create node", "Node is not covered by the workspace filter as defined in filter.xml");
return null;
}
Repository repository = ServerUtil.getDefaultRepository(node.getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
if (!doNotAskAgain) {
MessageDialog dialog = new MessageDialog(null, "Unable to validate node type", null, "Unable to validate node types since project " + node.getProject().getName() + " is not associated with a server or the server is not started.", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "Continue (do not ask again)", "Continue" }, 1) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
};
int choice = dialog.open();
if (choice <= 0) {
return null;
}
if (choice == 1) {
doNotAskAgain = true;
}
}
}
final NodeType nodeType = node.getNodeType();
if (nodeType != null && nodeType.getName() != null && nodeType.getName().equals("nt:file")) {
MessageDialog.openInformation(shell, "Cannot create node", "Node of type nt:file cannot have children");
return null;
}
try {
final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
if (nnd.open() == IStatus.OK) {
node.createChild(nnd.getValue(), nnd.getChosenNodeType());
return null;
}
} catch (RepositoryException e1) {
Activator.getDefault().getPluginLogger().warn("Could not open NewNodeDialog due to " + e1, e1);
}
return null;
}
use of org.apache.sling.ide.transport.Repository in project sling by apache.
the class SlingLaunchpadBehaviour method start.
public void start(IProgressMonitor monitor) throws CoreException {
boolean success = false;
Result<ResourceProxy> result = null;
monitor = SubMonitor.convert(monitor, "Starting server", 10).setWorkRemaining(50);
Repository repository;
RepositoryInfo repositoryInfo;
OsgiClient client;
try {
repository = ServerUtil.connectRepository(getServer(), monitor);
repositoryInfo = ServerUtil.getRepositoryInfo(getServer(), monitor);
client = Activator.getDefault().getOsgiClientFactory().createOsgiClient(repositoryInfo);
} catch (CoreException e) {
setServerState(IServer.STATE_STOPPED);
throw e;
} catch (URISyntaxException e) {
setServerState(IServer.STATE_STOPPED);
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
// 10/50 done
monitor.worked(10);
try {
EmbeddedArtifactLocator artifactLocator = Activator.getDefault().getArtifactLocator();
// 15/50 done
installBundle(monitor, client, artifactLocator.loadSourceSupportBundle(), SUPPORT_SOURCE_BUNDLE_SYMBOLIC_NAME);
// 20/50 done
installBundle(monitor, client, artifactLocator.loadToolingSupportBundle(), SUPPORT_BUNDLE_SYMBOLIC_NAME);
} catch (IOException | OsgiClientException e) {
Activator.getDefault().getPluginLogger().warn("Failed reading the installation support bundle", e);
}
try {
if (getServer().getMode().equals(ILaunchManager.DEBUG_MODE)) {
debuggerConnection = new JVMDebuggerConnection(client);
success = debuggerConnection.connectInDebugMode(launch, getServer(), SubMonitor.convert(monitor, 30));
// 50/50 done
} else {
Command<ResourceProxy> command = repository.newListChildrenNodeCommand("/");
result = command.execute();
success = result.isSuccess();
// 50/50 done
monitor.worked(30);
}
if (success) {
setServerState(IServer.STATE_STARTED);
} else {
setServerState(IServer.STATE_STOPPED);
String message = "Unable to connect to the Server. Please make sure a server instance is running ";
if (result != null) {
message += " (" + result.toString() + ")";
}
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message));
}
} catch (CoreException | RuntimeException e) {
setServerState(IServer.STATE_STOPPED);
throw e;
} finally {
monitor.done();
}
}
use of org.apache.sling.ide.transport.Repository in project sling by apache.
the class JcrNode method getNodeType.
public NodeType getNodeType() {
Repository repository = ServerUtil.getDefaultRepository(getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
return null;
}
return ntManager.getNodeType(getPrimaryType());
}
use of org.apache.sling.ide.transport.Repository in project sling by apache.
the class JcrNode method getSerializationKind.
private SerializationKind getSerializationKind(String nodeType) {
final SerializationKindManager skm = new SerializationKindManager();
final Repository repo = ServerUtil.getDefaultRepository(getProject());
if (repo == null) {
return getFallbackSerializationKind(nodeType);
}
try {
skm.init(repo);
//TODO: mixins not yet supported
return skm.getSerializationKind(nodeType, new ArrayList<String>());
} catch (RepositoryException e) {
e.printStackTrace();
return getFallbackSerializationKind(nodeType);
}
}
use of org.apache.sling.ide.transport.Repository in project sling by apache.
the class JcrEditingSupport method doGetCellEditor.
protected CellEditor doGetCellEditor(Object element) {
if (!canEdit(element)) {
return null;
}
switch(columnId) {
case NAME:
{
// no validator needed - any string is OK
return new TextCellEditor(tableViewer.getTable());
}
case TYPE:
{
// using a dropdown editor
final ComboBoxCellEditor editor = new ComboBoxCellEditor(tableViewer.getTable(), PropertyTypeSupport.PROPERTY_TYPES, SWT.NONE);
editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION);
return editor;
}
case VALUE:
{
final Field field = asField(element);
if (getNode().getProperty(field.getPropertyName()).isMultiple()) {
// then launch the MVPEditor instead of returning an editor here
return new MVNCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.DATE) {
return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.BOOLEAN) {
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
CellEditor editor;
if (field.getPropertyName().equals("jcr:primaryType")) {
editor = new TextCellEditor(tableViewer.getTable()) {
@Override
protected Control createControl(Composite parent) {
Text text = (Text) super.createControl(parent);
Repository repository = ServerUtil.getDefaultRepository(getNode().getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
return text;
}
try {
Collection<String> types = ntManager.getAllowedPrimaryChildNodeTypes(getNode().getParent().getPrimaryType());
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(types.toArray(new String[0]));
proposalProvider.setFiltering(true);
ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
return text;
} catch (RepositoryException e) {
return text;
}
}
};
} else {
editor = new TextCellEditor(tableViewer.getTable());
}
// value might require a validator depending on the property type
int propertyType = getNode().getPropertyType(field.getPropertyName());
switch(propertyType) {
case PropertyType.STRING:
case PropertyType.NAME:
{
//TODO: check jcr rules for name
break;
}
case PropertyType.DECIMAL:
{
editor.setValidator(new DecimalValidator(editor));
break;
}
default:
{
//TODO
break;
}
}
return editor;
}
case MULTIPLE:
{
if (element instanceof NewRow) {
return null;
}
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
default:
{
throw new IllegalStateException("Unknown columnId: " + columnId);
}
}
}
Aggregations