I have few meeting request in my native calendar scheduled for different date and time,i am trying to read the entire events scheduled for a specific date using the folloing code.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items();
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
if(eventList.isSupportedField(Event.SUMMARY) && event.countValues(Event.SUMMARY) > 0) {
String subject = event.getString(Event.SUMMARY, 0);
Dialog.alert(subject);
}
}
}
catch (PIMException e) {
Dialog.alert(e.getMessage());
}
}
I am able to get the subject from native calendar ,but i want the code to read the meetings along with date and time,I am not able to do this.
The Date/Times of events are stored in the fields Event.START and Event.END as long values containing the number of milliseconds since the Unix epoch. See my answer to this question, and the API documents for the Event interface.
Related
I'm using Vaadin Calendar component with EventProvider. It loads items corrently when displayed inititaly, but when I edit the calendar item it doest reflect changes on the screen. (caption name change or date changes) I even tried to set provider once again after entry update cal.setEventProvider(p); but it doesnt force calendar to fetch fresh data from provider. Any hint how to work with EventProvider and do entries updates on calendar?
I had a very similar problem a while back (Vaadin 7.1), and found out that the default implementation of ContainerEventProvider doesn't work properly. I do not remember all the details but my investigation showed a problem with the getEvents method. To solve it, I subclassed ContainerEventProvider with my own class and implemented an override of getEvents:
#Override
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
eventCache.clear();
// int[] rangeIndexes = getFirstAndLastEventIndex(startDate, endDate);
for (int i = 0; i < container.size(); i++) {
eventCache.add(getEvent(i));
}
return Collections.unmodifiableList(eventCache);
}
And this is the function that assigns a container to the calendar:
public void setCalendarContainerDataSource(Indexed ds) {
// this.vaadinCal.setContainerDataSource(ds); // this did't work
MyCalendarContainerEventProvider provider = new MyCalendarContainerEventProvider(ds);
provider.addEventSetChangeListener(new CalendarEventProvider.EventSetChangeListener() {
public void eventSetChange(EventSetChangeEvent changeEvent) {
vaadinCal.markAsDirty();
}
});
provider.addEventChangeListener(new EventChangeListener() {
public void eventChange(EventChangeEvent changeEvent) {
// Repaint if event changes
vaadinCal.markAsDirty();
}
});
vaadinCal.setEventProvider(provider);
}
I've got:
my-app
community-list
On attached, my-app gets the user and loads the app.user. In the meantime, community-list is attached (even before app.user is loaded) and so I haven't been able to get the user's starred communities yet. Therefore, the solution I'm working on is as follows.
In community-list.attached():
app.changes.listen((List<ChangeRecord> records) {
if (app.user != null) {
getUserStarredCommunities();
}
});
Elsewhere in community-list is said metho:
// This is triggered by an app.changes.listen.
void getUserStarredCommunities() {
// Determine if this user has starred the community.
communities.forEach((community) {
var starredCommunityRef = new db.Firebase(firebaseLocation + '/users/' + app.user.username + '/communities/' + community['id']);
starredCommunityRef.onValue.listen((e) {
if (e.snapshot.val() == null) {
community['userStarred'] = false;
} else {
community['userStarred'] = true;
}
});
});
}
Note that communities is an observable list in community-list:
#observable List communities = toObservable([]);
Which is initially populated in community-list.attached():
getCommunities() {
var f = new db.Firebase(firebaseLocation + '/communities');
var communityRef = f.limit(20);
communityRef.onChildAdded.listen((e) {
var community = e.snapshot.val();
// If no updated date, use the created date.
if (community['updatedDate'] == null) {
community['updatedDate'] = DateTime.parse(community['createdDate']);
}
// snapshot.name is Firebase's ID, i.e. "the name of the Firebase location"
// So we'll add that to our local item list.
community['id'] = e.snapshot.name();
// Insert each new community into the list.
communities.add(community);
// Sort the list by the item's updatedDate, then reverse it.
communities.sort((m1, m2) => m1["updatedDate"].compareTo(m2["updatedDate"]));
communities = communities.reversed.toList();
});
}
In summary, I load the list of communities even before I have a user, but once I have a user I want to update each community (Map) in the list of communities with the userStarred = true/false, which I then use in my community-list template.
Alas, it doesn't seem like the List updates. How do I achieve this?
This whole app.changes.listen business is expensive. What's the proper practice in a case like this, where an element is loaded before I load objects (like app.user) that will modify it in some way.
1)
toList() creates a copy of the list. You need to apply toObservable again to get an observable list.
communities = toObservable(communities.reversed.toList());
This also assigns a new list to communities which is covered by #observable.
I think it should trigger anyway
2) You update your communities explicitly. It shouldn't be necessary to listen for changes. You can call a method containing
if (app.user != null) {
getUserStarredCommunities();
}
explicitly each time you change the list.
You also call Firebase for each community when a change in communities occurs. I don't know Firebase but it seems you send a request to a server each time which is of course expensive.
You should remember for what user+community combination you already made the call and use the remembered result instead.
With app.changes.listen you listen to any updated of any #observable field in your component. If you have other observable fields beside communities this method might be called too often.
If you are only interested in changes to communities you should put this code into a method like
communitiesChanged(oldVal, newVal) {
if (app.user != null) {
getUserStarredCommunities();
}
}
but the better option is to not listen to changes and another method name and call it explicitly as state above anyways if possible.
I am trying to list all the events from a native calendar using the code below.
I am getting an object, and I want the exact event string.
I have set a meeting in my calendar and I want to read the same.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items()
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
Dialog.alert(event.toString());
}
} catch (PIMException e) {
Dialog.alert(e.getMessage());
}
}
I have added a meeting as a event in calendar and i want to read this.
I'm not sure exactly what you want but for example if you wanted to read the subject line you could do something like this:
if(eventList.isSupportedField(BlackBerryEvent.SUMMARY) && event.countValues(BlackBerryEvent.SUMMARY) > 0) {
subject = event.getString(BlackBerryEvent.SUMMARY, 0);
}
I have written an add in that takes the active document as a parameter. So each time that the active document has changed, I need to know. To do so, I wanted to use "Events.DocumentEvents.DocumentOpened" event of the DTE2 object. But the problem is that event is never get fired even though I change the active document.
The code snippet is as follows
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_applicationObject.Events.DocumentEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(DocumentEvents_DocumentOpened);
...
}
void DocumentEvents_DocumentOpened(Document Document)
{
MessageBox.Show("Not called");
}
I have tried with DocumentEvents as well but no success. Any ideas?
I had just realized that I focused on the wrong event and thats why it was not fired. With the code below I got what I intended to. So instead of DocumentEvents, I had to use WindowEvents.
....
_applicationObject.Events.WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowEvents_WindowActivated);
}
void WindowEvents_WindowActivated(Window GotFocus, Window LostFocus)
{
if (ucCAST != null && GotFocus.Document != null)
((CAST)ucCAST).refreshCode(GotFocus.Document.Name);
}
I'm in need of creation of a web part which takes input from a task list and changes the color of the tasklist based on the data in the task list. Can anyone help me with this problem?
I can write code in visual studio 2005.
My question is how do I take input data from the list?
Sample code here. This should get you started. (source)
using Microsoft.SharePoint;
class SPTest {
public void ReadList() {
// Use using to make sure resources are released properly
using(SPSite oSite = new SPSite(pathToSite)) {
using(SPWeb oWeb = oSite.AllWebs[nameOfWeb]) {
// Alternately you can use oSite.RootWeb if you want to access the main site
SPList oList = oWeb.Lists[listName]; // The display name, ie. "Calendar"
foreach(SPListItem oItem in oList.Items) {
// Access each item in the list...
DateTime startTime = (DateTime)oItem["Start Time"];
// etc....
}
}
}
}
}