e33aa347f124961ccc1f6b9bb8762b7d7be9d425
[public/netxms.git] / android / src / console / src / org / netxms / ui / android / main / fragments / InterfacesFragment.java
1 /**
2 *
3 */
4 package org.netxms.ui.android.main.fragments;
5
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Set;
9
10 import org.netxms.client.objects.AbstractObject;
11 import org.netxms.client.objects.Interface;
12 import org.netxms.ui.android.R;
13 import org.netxms.ui.android.loaders.GenericObjectChildrenLoader;
14 import org.netxms.ui.android.main.adapters.InterfacesAdapter;
15
16 import android.os.Bundle;
17 import android.support.v4.app.LoaderManager;
18 import android.support.v4.content.Loader;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22
23 /**
24 * Fragment for last values info
25 *
26 * @author Marco Incalcaterra (marco.incalcaterra@thinksoft.it)
27 *
28 */
29
30 public class InterfacesFragment extends ExpandableListFragment implements LoaderManager.LoaderCallbacks<Set<AbstractObject>>
31 {
32 private InterfacesAdapter adapter = null;
33 private final GenericObjectChildrenLoader loader = null;
34
35 @Override
36 public View onCreateView(LayoutInflater inflater, ViewGroup container,
37 Bundle savedInstanceState)
38 {
39 View v = inflater.inflate(R.layout.interfaces_fragment, container, false);
40 createProgress(v);
41 return v;
42 }
43
44 @Override
45 public void onActivityCreated(Bundle savedInstanceState)
46 {
47 super.onActivityCreated(savedInstanceState);
48 adapter = new InterfacesAdapter(getActivity(), null, null);
49 setListAdapter(adapter);
50 setListShown(false, true);
51 GenericObjectChildrenLoader loader = (GenericObjectChildrenLoader)getActivity().getSupportLoaderManager().initLoader(R.layout.interfaces_fragment, null, this);
52 if (loader != null)
53 {
54 loader.setObjId(nodeId);
55 loader.setClassFilter(AbstractObject.OBJECT_INTERFACE);
56 loader.setService(service);
57 }
58 }
59
60 @Override
61 public void refresh()
62 {
63 if (loader != null)
64 {
65 loader.setObjId(nodeId);
66 loader.setService(service);
67 loader.forceLoad();
68 }
69 }
70
71 /* (non-Javadoc)
72 * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onCreateLoader(int, android.os.Bundle)
73 */
74 @Override
75 public Loader<Set<AbstractObject>> onCreateLoader(int arg0, Bundle arg1)
76 {
77 return new GenericObjectChildrenLoader(getActivity());
78 }
79
80 /* (non-Javadoc)
81 * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onLoadFinished(android.support.v4.content.Loader, java.lang.Object)
82 */
83 @Override
84 public void onLoadFinished(Loader<Set<AbstractObject>> arg0, Set<AbstractObject> arg1)
85 {
86 setListShown(true, true);
87 if (adapter != null)
88 {
89 List<Interface> interfaces = null;
90 if (arg1 != null)
91 {
92 interfaces = new ArrayList<Interface>();
93 for (AbstractObject go : arg1)
94 interfaces.add((Interface)go);
95 }
96 adapter.setValues(interfaces);
97 adapter.notifyDataSetChanged();
98 }
99 }
100 /* (non-Javadoc)
101 * @see android.support.v4.app.LoaderManager.LoaderCallbacks#onLoaderReset(android.support.v4.content.Loader)
102 */
103 @Override
104 public void onLoaderReset(Loader<Set<AbstractObject>> arg0)
105 {
106 }
107 }