Bug 294777 [context] Clarify default state of @Optional
The "@Optional" annotation now is mixed up about its default state. The Javadoc says that its default state is "true", while some code paths think it is "false". What we need to consider: - in *all* cases in demos we have so far we use "@Optional(true)" - the original intent was (AFAIK): constructors: default is @Optional(false) method arguments: default is @Optional(false) methods on #make: default should be @Optional(true) ? I'd like to propose the following scheme based on the patters we see in demos: - arguments (of either method or constructor) are required by default - calling injectable methods [and setting fields] is optional by default This would mean that any explicit calls (#invoke(), #make()) must have their arguments available in the context to succeed. However, any calls generated by DI behind the scene (as a result of #inject()) are optional. On, in other terms, we don't have to call injectable methods unless specifically instructed. However, if we do call a method, we expect its arguments to be in the context. (This, of course, is the deafult state and can be change by using @Optional annotation.) The upside of this approach is that it fits well into patterns we see in the E4 demos (= DI "just works"). The downside is that, as evident from this text, it is not that easy to explain exactly what are the default states. From simplicicty of the programming model, it would be much better to just say that the default is always true or always false. Any opinions on this proposal?
examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailsView.java
}
	@Inject
	@Optional
	public void setSelection(@Optional @Named(IServiceConstants.SELECTION) Contact contact) {
		if (contact != null) {
			if (dirtyable.isDirty()) {
				MessageDialog dialog = new MessageDialog(detailComposite
						.getShell(), "Save vCard", null,
						"The current vCard has been modified. Save changes?",
						MessageDialog.CONFIRM, new String[] {
								IDialogConstants.YES_LABEL,
								IDialogConstants.NO_LABEL }, 0);
				dialog.create();
				ThemeUtil.applyDialogStyles(engine, dialog.getShell());
				if (dialog.open() == Window.OK) {
					ParameterizedCommand saveCommand = commandService
							.createCommand("contacts.save",
									Collections.EMPTY_MAP);
					handlerService.executeHandler(saveCommand);
				}
			}
			updatePartTitle(contact);
		} else {
			uiItem.setName("Details");
		}
		dirtyable.setDirty(false);
		detailComposite.update(contact);
	}
}